reactjs - 如何在 momentjs 中获取 endOf day toISOString() 但毫秒应该是 .000Z 而不是 .999Z
问题描述
基本上我有一个约会:
const now = moment()
console.log(now.endOf('day').toISOString()) // 2021-10-25T21:59:59.999Z
我希望它为:2021-10-25T21:59:59.000Z
作为一个走动我做了
console.log(`${moment().endOf('day').utc().format('YYYY-MM-DDTHH:mm:ss')}.000Z`)
得到了我想要的打印输出,但是
也许有人有更优雅的方式?
感谢人们!
解决方案
或者,您可以将 the 转换moment
为 a Date
(或仅使用Date
它自己),并使用Date.prototype.setUTCHours()
with0
作为第四个参数(毫秒):
const now = new Date()
now.setUTCHours(23,59,59,0) // end of day
console.log(now.toISOString())
推荐阅读
- php - PHP Mysql重连问题:
- python - Python - 仅替换字符串中的字母一次
- authorization - oracle apex中如何根据不同区域向授权方案发送参数
- ios - 在 iOS 上将附件数据字符串从 Gmail API 转换为数据始终返回 nil
- python - 强制 pip 从源 (tar.gz) 构建,而不是轮子 (.whl)
- github - Github - 如何合并到远程功能分支
- python - 多线程:两个线程与嵌套线程 Python
- swift - Xcode 12 In App Purchase Implementation - SKProductsRequestDelegate 没有被调用
- php - PHP的价格中断数量
- css - React 组件定位