문제

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.

도움이 되었습니까?

해결책

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)

다른 팁

You could try using moment.js for date/time manipulation

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

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top