以秒为单位获取当前日期/时间-JavaScript?
首先,获取当前日期-
var currentDateTime = new Date();
要获取以秒为单位的当前日期/时间,请使用getTime()/1000。
示例
以下是代码-
var currentDateTime = new Date();
console.log("当前日期时间如下:");
console.log(currentDateTime);
var resultInSeconds=currentDateTime.getTime() / 1000;
console.log("当前日期时间(以秒为单位)如下:")
console.log(resultInSeconds);要运行上述程序,您需要使用以下命令-
node fileName.js.
在这里,我的文件名为demo285.js。
输出结果
这将在控制台上产生以下输出-
当前日期时间如下: 2020-08-28T16:13:35.987Z 当前日期时间(以秒为单位)如下: 1598631215.987
热门推荐
10 圣诞祝福语简短小学
11 祖国七十华诞简短祝福语
12 老师送的祝福语简短
13 生日祝福语大全女生简短
14 祝女性生日祝福语简短
15 牛年女神节祝福语简短
16 情人表白祝福语简短大气
17 老公开业祝福语简短
18 官宣新年祝福语简短