I am saving data in MongoDB server from Node.js application (using Mongoose).
Consider following code:
var mongoose = require(\'mongoose\');
var Schema =
for ISO use toISOString()
var today = new Date();
var ISOstring = today.toISOString();
// 2020-08-03T23:59:58.123Z
GMT and UTC are different timezones, they are Greenwich Mean Time and Coordinated Universal Time respectively. GMT is a 'solar' timezone, whereas UTC is 'atomic'. For most purposes they are essentially the same thing, however UTC is more 'universal'.
Interestingly the documentation you point to for toUTCString
still show a GMT output:
var today = new Date();
var UTCstring = today.toUTCString();
// Mon, 03 Jul 2006 21:44:38 GMT
For interchange of data between application I would prefer to use something like ISO8601, which uses the 'Z' suffix for UTC:
2013-01-16T08:19Z
Where the 'Z' confusingly stands for 'Zulu time'!
From what I can see they are the same. And the documentation at MDN already states that toGMTString
has been deprecated in favor of toUTCString
:
toGMTString() is deprecated and should no longer be used. It remains implemented only for backward compatibility; please use toUTCString() instead.
Mostly use for formatting date and time (Human Readable). You can also use toLocaleDateString()
var event = new Date(Date.UTC(2012, 11, 20, 3, 0, 0));
var options = { weekday: 'short', year: 'numeric', month: 'short', day: 'numeric' };
console.log(event.toLocaleDateString('en-US', options));