如何使用javascript或jquery将时间转换为javascript时间戳?
如何将此时间如何使用javascript或jquery将时间转换为javascript时间戳?,javascript,jquery,time,timestamp,Javascript,Jquery,Time,Timestamp,如何将此时间11:34转换为javascript时间戳。任何可用的javascript功能 我正在尝试为我正在使用的Flot库创建一个Flot图。在我的图表中,时间在x轴上,计数在y轴上。为了创建数据部分,我需要将时间转换为API文档中指定的时间戳 这是我的密码 var datasets = { "usa": { label: "Logged Users", data: [[10:55, 4], [11:00, 1], [11:05, 4], [11:1
11:34
转换为javascript时间戳。任何可用的javascript功能
我正在尝试为我正在使用的Flot库创建一个Flot图。在我的图表中,时间在x轴上,计数在y轴上。为了创建数据部分,我需要将时间转换为API文档中指定的时间戳
这是我的密码
var datasets = {
"usa": {
label: "Logged Users",
data: [[10:55, 4], [11:00, 1], [11:05, 4], [11:10, 2], [11:15, 3], [11:20, 1], [11:25, 5]]
}
};
if (datasets.length > 0){
$.plot($("#placeholder"), datasets, {
yaxis: { min: 0,tickDecimals: 0 },
xaxis: { mode: "time",timeformat: "%H:%M" }
});
}
它不起作用,因为我指定了确切的时间而不是数字。所以我需要将其转换为时间戳格式。请帮帮我 谢谢请使用以下实例: 另见 ==更新=== 如果时间是本地时间而不是UTC,则可以使用以下设置时间:
oDate.setHours(
parseInt(sTime.substr(0, 2), 10),
parseInt(sTime.substr(3, 2), 10),
0,
0
);
另见
注意:getTime()
的结果以毫秒为单位
==更新===
要映射当前数据集,可以使用以下脚本(使用UTC;如果需要本地时间,请在setter中删除UTC):
var accountries=[“美国”];
var oDate=新日期();
oDate.setSeconds(0,0);
对于(变量i=0;i
另请参见。我发现日期解析最有效。其他方法存在跨浏览器问题,date.js等内容已经有一段时间没有更新了
页面上也不需要日期选择器。您可以调用与文档中给出的示例类似的内容:
$.parseDate('yy-mm-dd', '2007-01-26');
它是记录事件的时间戳还是什么,请详细描述您想要的内容?请注意,时间戳始终包含“日期”部分(即当前日期)。除非创建自己的类型,否则无法在JavaScript中创建“仅小时”时间戳。
var aCountries = [ "usa" ];
var oDate = new Date();
oDate.setSeconds(0, 0);
for (var i = 0; i < aCountries.length; i++) {
datasets[aCountries[i]].data =
datasets[aCountries[i]].data.map(function(oElement) {
oDate.setUTCHours(
parseInt(oElement[0].substr(0, 2), 10),
parseInt(oElement[0].substr(3, 2), 10)
);
return [
oDate.getTime()
, oElement[1]
];
});
}
var now = new Date();
now.format("m/dd/yy");
// Returns, e.g., 6/09/07
// Can also be used as a standalone function
dateFormat(now, "dddd, mmmm dS, yyyy, h:MM:ss TT");
// Saturday, June 9th, 2007, 5:46:21 PM
// You can use one of several named masks
now.format("isoDateTime");
// 2007-06-09T17:46:21
// ...Or add your own
dateFormat.masks.hammerTime = 'HH:MM! "Can\'t touch this!"';
now.format("hammerTime");
// 17:46! Can't touch this!
// When using the standalone dateFormat function,
// you can also provide the date as a string
dateFormat("Jun 9 2007", "fullDate");
// Saturday, June 9, 2007
// Note that if you don't include the mask argument,
// dateFormat.masks.default is used
now.format();
// Sat Jun 09 2007 17:46:21
// And if you don't include the date argument,
// the current date and time is used
dateFormat();
// Sat Jun 09 2007 17:46:22
// You can also skip the date argument (as long as your mask doesn't
// contain any numbers), in which case the current date/time is used
dateFormat("longTime");
// 5:46:22 PM EST
// And finally, you can convert local time to UTC time. Either pass in
// true as an additional argument (no argument skipping allowed in this case):
dateFormat(now, "longTime", true);
now.format("longTime", true);
// Both lines return, e.g., 10:46:21 PM UTC
// ...Or add the prefix "UTC:" to your mask.
now.format("UTC:h:MM:ss TT Z");
// 10:46:21 PM UTC
Use all date time example .,so use it.
$.parseDate('yy-mm-dd', '2007-01-26');