Javascript moment.js 获取昨天从午夜到午夜的时间范围

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/31593445/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-23 06:52:55  来源:igfitidea点击:

moment.js get yesterday time range from midnight to midnight

javascriptmomentjs

提问by user2818430

How can I get the time range for yesterday from midnight until midnight:

如何获得昨天从午夜到午夜的时间范围:

Example:

例子:

Yesterday 22.07.2015

昨天 22.07.2015

Result:

结果:

22.07.2015 00:00:00 (AM)

22.07.2015 00:00:00 (上午)

22.07.2015 23:59:59 (PM)

22.07.2015 23:59:59 (下午)

Date format doesn't matter this is just an example.

日期格式无关紧要这只是一个例子。

回答by Jason H

moment().subtract(1,'days').startOf('day').toString()

"Thu Jul 30 2015 00:00:00 GMT-0600"

“2015 年 7 月 30 日星期四 00:00:00 GMT-0600”

moment().subtract(1,'days').endOf('day').toString()

"Thu Jul 30 2015 23:59:59 GMT-0600"

“2015 年 7 月 30 日星期四 23:59:59 GMT-0600”