以秒为单位获取当前日期/时间-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
热门推荐
1 如何训练狗狗不叫
2 训练狗狗不叫
3 训练狗狗随行
4 怎么训练狗狗不叫
7 训练比熊狗狗教程
10 上海狗狗训练
11 怎么训练狗狗上厕所
12 训练狗狗趴下
13 狗狗服从训练
14 训练狗狗拒食
15 训练狗狗笑
16 训练狗狗大便
17 训练狗狗立
18 训练狗狗捡东西