I am saving data in MongoDB server from Node.js application (using Mongoose).
Consider following code:
var mongoose = require('mongoose');
var Schema = mongoose.Schema;
var schemaObj = new Schema({
field1: String,
field2: String,
Datefield: Date//So on...
});
mongooseDB = mongoose.createConnection('mongodb://myserver:port/DBname');
mongooseDB.on('error', console.error.bind(console, 'error in connection'));
mongooseDB.once('open', function (err) {
var objmodel = db.model('myschema', schemaObj);
modelObj.field1 ='value1';
modelObj.Datefield = new Date().toGMTString(); //new Date().toUTCString();
//So on..
modelObj.save(function (err) {
if (err)
//Notify err
else
//DO some task after save
});
});
In the Datefield, Getting following value when I use 'toGMTstring()' or 'toUTCstring()'
'Thu, 24 Jan 2013 05:49:04 GMT'
I went through the following links:
toGMTString is deprecated and should no longer be used
Could anyone help me in understanding, whats the difference between toUTCstring() and toGMTstring() with respect to Node.js?
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'!
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With