以秒为单位获取当前日期/时间-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 庆祝当生日祝福语简短