Jump to content
Sign in to follow this  

Insert date into object

Recommended Posts

How can I add a date to an object without it changing due to the timezone? 


var mydate1 = new Date('2019-12-10 00:00:00');
var myobject1 = {"mydate": mydate1};

alert(mydate1 + "  -  " + JSON.stringify(myobject1));

Result is:   

Tue Jan 01 2019 00:00:00 GMT+0100 (Ora standard dell’Europa centrale)  -  {"mydate":"2018-12-31T23:00:00.000Z"}

Thank you.

Share this post

Link to post
Share on other sites

It's not the object that's the problem, it's JSON.stringify().

Share this post

Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Sign in to follow this  

  • Create New...