The date and time is converted from local time to a UTC-based number inside the Date object. This means you can call methods on Date to find it’s UTC value. You can use other methods to see what that the time is locally too. Whenever you are sending dates to another system (e.g. a web server) it is often wise to send them as UTC.
- If you need to pass dates around your program, keep them as Date objects if possible.
- When sending dates to a server or service, use the
toISOStringto format the date because it is a standard format and uses UTC. Alternatively use the
getTimeto get the number of milliseconds since 01/01/1970, and this is also in UTC.
- When receiving dates from a server or service, if you have any control or influence, try to make sure they are sent as an ISO string or milliseconds since 01/01/1970, and then you can pass them as the argument to
- Only use the
toUTCString, etc. methods for strings that will be shown to a user of your web page.
- Be careful when using libraries with calendar controls, and read the documentation about what date format’s they expect to work with.
And take a look of the list with the most popular JS open source repositories on GitHub in March!