I want to change my datetime : "2015-02-16 11:03:19.000000" into unix timestamp using javascript. I have tried the below code but its not wokring:-
我想使用javascript将我的日期时间:“2015-02-16 11:03:19.000000”更改为unix时间戳。我尝试了下面的代码,但它没有问题: -
var d = new Date("2015-02-16 11:03:19.000000");
document.write(d.getTime() + " milliseconds since 1970/01/01");
2 个解决方案
#1
0
try using alert for you to see
尝试使用警报让你看
var d = new Date("2015-02-16 11:03:19.000000");
alert(d.getTime() + " milliseconds since 1970/01/01")
your code is working
你的代码正在运行
and look on this
看看这个
convert date to timestamp in javascript?
在javascript中将日期转换为时间戳?
How do you get a timestamp in JavaScript?
你如何获得JavaScript的时间戳?
#2
0
because your dateString style cannot be recognized by Date() Object. I have tried your code in Chrome, IE and Firefox. it works in Chrome, but not in Firefox and IE. so I recommend you try the method below.
因为Date()对象无法识别您的dateString样式。我在Chrome,IE和Firefox中尝试过您的代码。它适用于Chrome,但不适用于Firefox和IE。所以我建议你尝试下面的方法。
Date() Object accepts four kinds of input.
Date()对象接受四种输入。
- new Date();
- new Date(value);
- new Date(dateString);
- new Date(year, month[, day[, hour[, minutes[, seconds[, milliseconds]]]]]);
新日期(年,月[,日[,小时[,分钟[,秒[,毫秒]]]]]);
if you choose dateString, you should enter string like "2015-02-16" or "2015-02-16T11:03:19" (date and time) can be passed and parsed. The UTC time zone is used to interpret arguments in ISO 8601 format that do not contain time zone information (note that ECMAScript ed 6 draft specifies that date time strings without a time zone are to be treated as local, not UTC).
如果选择dateString,则应输入字符串,如“2015-02-16”或“2015-02-16T11:03:19”(日期和时间)可以传递和解析。 UTC时区用于解释ISO 8601格式中不包含时区信息的参数(请注意,ECMAScript ed 6 draft指定不带时区的日期时间字符串将被视为本地,而不是UTC)。
and here is the relevant documention:https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date
以下是相关文档:https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date
#1
0
try using alert for you to see
尝试使用警报让你看
var d = new Date("2015-02-16 11:03:19.000000");
alert(d.getTime() + " milliseconds since 1970/01/01")
your code is working
你的代码正在运行
and look on this
看看这个
convert date to timestamp in javascript?
在javascript中将日期转换为时间戳?
How do you get a timestamp in JavaScript?
你如何获得JavaScript的时间戳?
#2
0
because your dateString style cannot be recognized by Date() Object. I have tried your code in Chrome, IE and Firefox. it works in Chrome, but not in Firefox and IE. so I recommend you try the method below.
因为Date()对象无法识别您的dateString样式。我在Chrome,IE和Firefox中尝试过您的代码。它适用于Chrome,但不适用于Firefox和IE。所以我建议你尝试下面的方法。
Date() Object accepts four kinds of input.
Date()对象接受四种输入。
- new Date();
- new Date(value);
- new Date(dateString);
- new Date(year, month[, day[, hour[, minutes[, seconds[, milliseconds]]]]]);
新日期(年,月[,日[,小时[,分钟[,秒[,毫秒]]]]]);
if you choose dateString, you should enter string like "2015-02-16" or "2015-02-16T11:03:19" (date and time) can be passed and parsed. The UTC time zone is used to interpret arguments in ISO 8601 format that do not contain time zone information (note that ECMAScript ed 6 draft specifies that date time strings without a time zone are to be treated as local, not UTC).
如果选择dateString,则应输入字符串,如“2015-02-16”或“2015-02-16T11:03:19”(日期和时间)可以传递和解析。 UTC时区用于解释ISO 8601格式中不包含时区信息的参数(请注意,ECMAScript ed 6 draft指定不带时区的日期时间字符串将被视为本地,而不是UTC)。
and here is the relevant documention:https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date
以下是相关文档:https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date