Use the following format, it will work in all browsers
var year = 2016; var month = 02; // month varies from 0-11 (Jan-Dec) var day = 23; month = month<10?"0"+month:month; // to ensure YYYY-MM-DD format day = day<10?"0"+day:day; dateObj = new Date(year+"-"+month+"-"+day); alert(dateObj);
// Your conclusion will look like this: "Wed 03.23.2006 00:00:00 GMT + 0530 (IST)"
// Note that this will be in the current time zone in this case, indicated by IST, to convert to UTC time zone, you can enable
alert(dateObj.toUTCSting);
// Your result will now like "Tue, 22 Mar 2016 18:30:00 GMT"
Note that dateObj now shows GMT time, also note that the date and time have been changed accordingly.
The "toUTCSting" function receives the corresponding time in the hryvnia meridian. This is achieved by setting the time difference between your current time zone and the Greenwich Meridian time zone.
In the above case, the time to conversion was 00:00 hours and minutes on March 23, 2016. And after switching from GMT + 0530 (IST) hours to GMT (it basically subtracts 5:30 hours from this timestamp in this case), the time is reflected at 18.30 hours on March 22, 2016 (exactly 5.30 hours for the first time).
To convert any date object to a timestamp, you can use
alert(dateObj.getTime());
// the output will be similar to this "1458671400000"
This will give you a unique timestamp.
Abhay Aradhya Feb 09 '16 at 10:10 2016-02-09 10:10
source share