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