我想将UTC日期和时间字符串转换为图表上x轴的当前时间。我很确定我没有正确使用Date.parse。任何帮助表示赞赏。感谢。
$.ajax({
url: "/chart/ajax_get_chart", // the URL of the controller action method
dataType: "json",
type: "GET",
success: function (result) {
var result = JSON.parse(result);
series = [];
for (var i = 0; i < result.length; i++) {
date = Date.parse(result[i]['date']);
tempArray = [parseFloat(result[i]['price'])];
series.push(tempArray);
series.push(date);
}
答案 0 :(得分:9)
Date.parse(result[i]['date']);
您刚刚将日期解析为返回值,然后完全忽略了结果。
您需要对返回值执行某些操作。
此外,Date.parse()
返回UNIX时间戳
要创建Date
个实例,请致电new Date(str)