我想将 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);
}
最佳答案
Date.parse(result[i]['date']);
您只是将日期解析为返回值,然后完全忽略了结果。
您需要对返回值执行一些操作。
此外,Date.parse()
返回 UNIX 时间戳。
要创建 Date
实例,请调用 new Date(str)
关于javascript - 如何将字符串转换为 JavaScript 日期对象?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17305318/