2014-12-04 45 views
1

我正在尝试以上格式的UTCString。我可以转换,问题是转换后显示前一天。将UTCString转换为yyyy-mm-dd

var newDate = this.getCellDate(target); 
    console.log(newDate); --> Dec 05 2014 00:00:00 GMT+0800 (Malay Peninsula Standard Time) 
    cstDate = newDate.toISOString(); 
    console.log(cstDate); -- > 2014-12-04 --- > **Expected --> 2014-12-05** 
+0

中有什么'getCellData()'方法?我认为你的问题在于此。 – 2014-12-04 09:25:59

+0

@MisterDood这是Sencha触摸日历功能... – 2014-12-04 09:26:38

+0

我收到日期,如果我点击日历的日期单元格 – 2014-12-04 09:26:58

回答

0

是的,我得到了解决方案。我不应该去看弦乐。相反,我需要使用toLocaleDateString

custdate = newDate.toLocaleDateString(); 
    dueDate= custdate.split("/").reverse().join("-"); 
1

使用Date.UTC()方法

var now = new Date(), // my date Thu Dec 04 2014 13:02:15 GMT+0300 (RTZ 2 (зима)) 
    year = now.getFullYear(), 
    month = now.getMonth(), 
    day = now.getDay(), 
    hours = now.getHours(), 
    minutes = now.getMinutes(), 
    utcDate; 

utcDate = new Date(Date.UTC(year, month, day, hours, minutes)); // Thu Dec 04 2014 16:02:00 GMT+0300 (RTZ 2 (зима)) 

Ext.Msg.alert('UTC Date', Ext.Date.format(utcDate, 'Y-m-d')); 

看看这个 “星期四2014年12月4日16:02:00” - 我得到了UTC时间(3小时)


Fiddle example

相关问题