JavaScript 数据转换器

JavaScript date convertor

我正在使用 Yahoo YQL API 来获取即将到来的板球比赛列表,现在的问题是 - 日期格式非常不同。我无法使用 JavaScript.

转换日期格式

从雅虎收到的日期格式: 2016-04-03T19:00:00+05:30
我需要的日期格式: 2016 年 4 月 3 日星期一

您可以使用Date.parse()来解析日期。

var date = Date.parse("2016-04-03T19:00:00+05:30");

您可以通过调用 Date 的成员手动格式化日期:

var days= ["Mon", "Thu", "Wed", "Thu", "Fri", "Sat", "Sun"];
var months = [ ... ];

var result = [];

// Day of week:
result.push(days[date.getDay()]); 

result.push(", ");

// Day of month:
result.push(date.getDate());

result.push(" ");

// Month:
result.push(months[date.getMonth()]); // Note that getMonth() is zero-based.

result.push(" ");

// Year:
result.push(date.getYear());

console.log(result.join(""));
var d = new Date('2016-04-03T19:00:00+05:30');

returns d 为

Sun Apr 03 2016 19:00:00 GMT+0530 (IST)

现在使用函数来获取像

这样的元素
d.getDate() returns 3

Date functions

试试这个:

var d = new Date('2016-04-03T19:00:00+05:30');
document.write(d.toUTCString().slice(0,16));

参考:http://www.w3schools.com/js/tryit.asp?filename=tryjs_date_toutcstring