javascript - 从 - new Date().getTime() 获取时间;
问题描述
我正在尝试获取设备的时间。我正在使用的代码是这样的 -
const estimatedDeviceTimeMs = new Date().getTime();
alert(new Date(estimatedDeviceTimeMs));
上面代码的结果是Thu Jul 30 2020 12:01:54 GMT+0530 (India Standard Time)
。
如果可能,我需要取出12:01:54
一个变量和GMT+0530
另一个变量。
解决方案
toTimeString
返回时间。然后按空间拆分以获得时间和时区,如下所示:
var date = new Date();
console.log(date.toTimeString().split(" ")[0]);
console.log(date.toTimeString().split(" ")[1]);
推荐阅读
- android - DynamoDB 嵌套项目插入 Android
- unity3d - 刚体 2D 不会停止
- javascript - 如何在 JavaScript 中的每个 for 循环迭代之间暂停
- node.js - Nest 无法解析 JobsService (?) 的依赖关系。请确保索引 [0] 处的参数 JobModel 在 AppModule 上下文中可用
- python - Python Socket 多个客户端 - 聊天应用程序
- c++ - C ++中具有相同值的多个键的数据结构
- python - Keras中临时合并batch维度
- assembly - 为什么我用了两次'mov ah,9',但屏幕只打印了一次?
- flutter - 如何处理 Listview.builder 中的多个复选框?
- conda - 未指定 numpy 版本:从 conda 配方中删除警告