ยท hands on
Convert to milliseconds
Learn how to get the milliseconds of a specific date in your desired timezone using Moment.js. You can use a predefined UTC offset or detect the UTC offset. You can also use a predefined time zone or detect the time zone.
Learn how to get the milliseconds of a specified date in your desired timezone.
Contents
Moment.js
Moment.js is a great library if you want to work with dates and times in TypeScript. It is very handy for creating interchange representations like ISO 8601 strings, taking your current timezone into account.
Convert to milliseconds
Let's say you live in Berlin (Germany), and you want to represent June, 26th of 2019 at midnight in milliseconds with Central European Summer Time (GMT+2). Using Moment.js v2.24 you have at least the following possibilities to do that:
Using a predefined UTC offset
Using UTC offset detection
Using a predefined time zone
Using time zone detection
Pro Tip: You can get date and time expressed according to ISO 8601 in TypeScript from the current date when calling:
Note that the above string will always be normalized to UTC time (Z). To prevent UTC conversion you have to call: