Reputation: 2672
I use date picker and i get the value of the date picker as
document.getElementById("id_of_datepicker")
and when i change this to date using
new Date(document.getElementById("id_of_datepicker"));
it returns
Thu Feb 06 2014 05:30:00 GMT+0530 (IST)
and what i look for is instead of passing the dates as i do i need to send it in local timezone with 00 hours, min, secs which then has to be converted to utc. how can i do this? please help me.
Upvotes: 1
Views: 465
Reputation: 12961
you have to split it manually and use Date.UTC
for utc function like this:
var dateStr = document.getElementById("id_of_datepicker");
var dateArr = dateStr.split(/[\-T:]/);//suppose it is like 2014-06-12T00:00:00
var localTime=new Date(Date.parse(dateArr[0],dateArr[1],dateArr[2]), 0, 0, 0)
var utcTime=new Date(Date.UTC(dateArr[0],dateArr[1],dateArr[2]), 0, 0, 0)
Upvotes: 1
Reputation: 2019
Suppose this the dt value returned by the date object Thu Feb 06 2014 05:30:00 GMT+0530 (IST)
Date dt=new Date();
dat=dt.getFullYear()+'-'+dt.getMonth()+'-'+dt.getDate();
It will return date dt print in yyyy-mm-dd format ot you can change in your desired format
Upvotes: 0