javascriptdatesetting

Javascript setting date not working, showing wrong hour


I want to set date and time to 2016-05-11T00:00:00.000Z

var date = new Date(2016,4,12,0,0,0,0);

but instead of showing Date 2016-05-11T00:00:00.000Z its giving Date 2016-05-11T19:00:00.000Z

I want time 00:00:00 but its giving 19:00:00


Solution

  • Use Date.UTC:

    Note: Where Date is called as a constructor with more than one argument, the specifed arguments represent local time. If UTC is desired, use new Date(Date.UTC(...)) with the same arguments. [Source]