This Gist aims to serve as a reminder for myself and for anybody who finds this useful. Documenting the various ways of converting time in javascript, making time and date stamps, adding and subtracting time into human-readable formats, the goal is to have snippets and references that are outside of the Mozilla docs, largely drawn from StackOverflow. Links will be provided as available.
It is advisable to keep times in UTC timezone, adjusting to timezones only after all other conversions have taken place. This document assumes UTC as the timezone.
Get the current timestamp with Date.now():
var current_time = Date.now();
> 1520362586914
Result is milliseconds since the Unix epoch of Jan 1, 1970 00:00:00 UTC
Use the Javascript built-in method .toISOString()
to convert to the ISO format
var current_iso_time = new Date(current_time).toISOString();
> "2018-03-06T18:56:26.914Z"