将UTC日期转换为日期时间字符串Titanium
我有一个日期字符串2012-11-14T06:57:36 + 0000,我想将其转换为以下格式2012年11月14日12:27。我尝试了很多解决方案,包括将UTC日期转换为日期时间字符串Javascript 。但没有什么可以帮助我。以下代码在android中为我工作。但对于ios,它显示为无效日期
I have a date string "2012-11-14T06:57:36+0000" that I want to convert to the following format "Nov 14 2012 12:27". I have tried a lot of solutions including Convert UTC Date to datetime string Javascript. But nothing could help me. The following code worked for me in android. But for ios it displays as invalid date
var date = "2012-11-14T06:57:36+0000";
//Calling the function
date = FormatDate(date);
//Function to format the date
function FormatDate(date)
{
var newDate = new Date(date);
newDate = newDate.toString("MMMM");
return (newDate.substring(4,21));
}
任何人都可以帮助我吗?提前致谢
Can anyone help me? Thanks in advance
所有浏览器都不支持相同的日期格式。我们可以选择的最佳方法是将字符串拆分为分隔符 - 和:,并将每个结果数组项传递给Date构造函数,请参阅以下函数
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
}