Javascript 时刻获取当前日期

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/38981976/
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 22:04:53  来源:igfitidea点击:

Moment get current date

javascriptmomentjs

提问by Ville Miekk-oja

How to get current date using the Moment library? Not timestamp, but date. So please don't refer to that timestamp question already to be found.

如何使用 Moment 库获取当前日期?不是时间戳,而是日期。所以请不要参考已经找到的时间戳问题。

I know how to get it in regular javascript, but I need a moment object with current date.

我知道如何在常规 javascript 中获取它,但我需要一个具有当前日期的时刻对象。

What about timezone, how to get current date in certain timezone?

时区怎么样,如何获取特定时区的当前日期?

回答by Rob M.

Just call moment as a function without any arguments:

只需将 moment 作为函数调用,不带任何参数:

moment()

For timezone information with moment, look at the moment-timezonepackage: http://momentjs.com/timezone/

有关时刻的时区信息,请查看moment-timezone包:http: //momentjs.com/timezone/