Convert UTC Date to datetime string Titanium

六眼飞鱼酱① 提交于 2019-12-05 20:33:59

All browsers doesn't support the same date formats. The best approach we can choose is to split the string on the separator characters -, and : , and pass each of the resulting array items to the Date constructor, see the following function

function FormatDate(date)
{   
    var arr = date.split(/[- :T]/), // from your example var date = "2012-11-14T06:57:36+0000";
    date = new Date(arr[0], arr[1]-1, arr[2], arr[3], arr[4], 00);
    newDate = date.toString("MMMM");
    //.. do further stuff here  
}
Aamir

You can get a Date object by initializing a new date:

var date = "2012-11-14T06:57:36+0000";
var newDate = new Date(date); // this will parse the format

console.log(newDate);
> Wed Nov 14 2012 01:57:36 GMT-0500 (EST)

As for the formatting, there are several threads (like this one) on that already.

There are also libraries for date formatting and processing that people usually end up using when doing a lot of date processing. I would suggest Datejs if you're looking for something like that.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!