好的,我有这个确切的日期:
2012-10-01T13:00:00+0000
我需要将其拆分为两个变量:一个是日期:2012-10-01,另一个是小时和分钟的时间:13:00
到目前为止我所生产的2012-09-12和14:00 - 完全错误的日期......
这是代码:
var d, dd, hh, mi, mm, theDate, theTime, yyyy;
var myDate = "2012-10-01T13:00:00+0000"; //Date I need converting into two variables
d = new Date(myDate);
yyyy = d.getFullYear().toString();
mm = d.getMonth().toString();
dd = d.getDate().toString();
hh = d.getHours().toString();
mi = d.getMinutes().toString();
theDate = yyyy + "-" + (mm[1] ? mm : "0" + mm[0]) + "-" + (dd[1] ? dd : "0" + dd[0]);
theTime = (hh[1] ? hh : "0" + hh[0]) + ":" + (mi[1] ? mi : "0" + mi[0]);
//theDate produces: 2012-09-12, (should be 2012-10-01)
//theTime produces: 14:00, (should be 13:00)