One of the complexities of working with Date and Time in software development is to keep track of the time zone to which the time is referring to. Date and Time are usually stored/sent/received as strings in the typical format:
'2020-08-13 14:30:00'
The problem is that this string does not mention the time zone used.
The Solution => The ECMA / ISO8601 Format.
ISO8601 is a date and time format that provides date, time and it's timezone as a single stirng.
ECMA is an interoperability standard which allows computer languages to understand each other. ECMA adopts ISO8601 date time format. ECMA is popular because it is adopted by almost all Javascript Compilers and Web Browsers.
In ECMA, The date and time will be in the following format:YYYY-MM-DDTHH:mm:ss.sssZ
Example:
2020-08-13T06:38:10.032ZThe
T in the middle means
TimeThe
Z at the end means the timezone is
UTC(These 2 Letters are
COMPULSORY for ECMA Compliance)
By using ECMA / ISO8601, compatibility with Javascript is ensured. Coding in Javascript becomes easy. Javascript powers angular, react and all popular frontend frameworks.
To convert a Javascript date object to ISO8601 string use: