1

How do I create a Javascript date without variable Timezone? Doing this in Javascript, gives a GMT Pacific standard below.

let test = new Date(new Date().getFullYear(), 0, 2, 0, 0, 0, 0)  },

test: Sat Feb 01 2020 00:00:00 GMT-0800 (Pacific Standard Time)}

Would like no timezone, or timezone set to 0.

  • 1
    What timezone do you want to create one with? A `Date` is basically a number that points to a moment in time, so something like a date without a timezone doesn't make sense. – Jacob Jun 05 '20 at 22:41
  • @Jacob make timezone zero –  Jun 05 '20 at 22:41
  • 1
    You mean UTC, GMT? Define 0. For me my time zone is zero and yours is pluses minuses wherever you come from. – Mike Doe Jun 05 '20 at 22:46
  • hi @emix yes, UTC GMT, for some reason Angular is presetting mine –  Jun 05 '20 at 22:47
  • 1
    Does this answer your question? [How do you convert a JavaScript date to UTC?](https://stackoverflow.com/questions/948532/how-do-you-convert-a-javascript-date-to-utc) – Triby Jun 05 '20 at 22:49
  • @Artportraitdesign1 that's not angular, that's a "feature" of your browser's JavaScript engine. Angular/Typescript is ultimately javascript when built. – Pac0 Jun 05 '20 at 23:06

1 Answers1

0

If by "make timezone zero" you mean to express the date/time in UTC, you can use Date.UTC:

const date = new Date(Date.UTC(2020, 1, 1)); // February 1, 2020, UTC midnight

You can use date.toISOString() if you also want the date presented in an ISO 8601 format, which will use the UTC 0 offset

Jacob
  • 77,566
  • 24
  • 149
  • 228
  • That's just how the date is output as a string. The date is UTC midnight, but `.toString()` on the Date presents it in your current timezone. – Jacob Jun 05 '20 at 22:54