Monday, 24 April 2017

How to save mongoose date-time in particular time-zone

Mongoose is saving date-time as ISODate("2017-04-25T09:40:48.193Z")in UTC format. How can i change its time zone to my local server timezone. So i need not to change the time every time i retrieve it from db. Here is my model schema:

var MyModelSchema = new mongoose.Schema(
    {
        id: Number,
        description: String,
        created: {type: Date},
        modified: {type: Date, default: Date.now},
    },
    {
        collection: 'my'
    }
);

PS: I am aware that it is preferred to save time in UTC format but here my requirement is to save it in specified time-zone.



via Saurabh Gupta

No comments:

Post a Comment