reactjs - 如何在 momentjs 中获取 endOf day toISOString() 但毫秒应该是 .000Z 而不是 .999Z

标签 reactjs angular react-native vue.js momentjs

基本上我有一个约会:

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`)

并得到了我想要的打印输出,但是

也许有人有更优雅的方式?

谢谢大家!

最佳答案

或者,您可以将时刻转换为日期(或仅使用日期本身),并使用Date.prototype.setUTCHours()0 作为第四个参数(毫秒):

const now = new Date()
now.setUTCHours(23,59,59,0) // end of day
console.log(now.toISOString())

关于reactjs - 如何在 momentjs 中获取 endOf day toISOString() 但毫秒应该是 .000Z 而不是 .999Z,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/69712943/

相关文章:

reactjs - create-react-app 的内容没有推送到 github

css - 如何在 Material ui 中覆盖处于禁用状态的复选框颜色(框和字体)?

angular - 使用 Angular cli 禁用 watch node_modules

react-native - 如何将 react-native 从 0.56.0 降级到 0.55.4 版本?

javascript - React Native fetch api 在转换为 json 之前检查 http 状态

javascript - 煎锅过滤器组件定制

javascript - 在循环中迭代和渲染 SVG

css - Accordion 打破了div的高度

Angular:有没有办法将 bool 值绑定(bind)到 CSS 类的存在?

ios - 在 iOS 上 native 找不到 RNFirebase 核心模块 - 未修复