In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-20 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)05/31 Report--
This article mainly introduces the relevant knowledge of "Moment.js common usage case analysis". The editor shows you the operation process through the actual case, and the operation method is simple, fast and practical. I hope this article "Moment.js common usage case analysis" can help you solve the problem.
Moment.js is a lightweight js time processing class library, which is easy to use, facilitates the operation of time in daily development, and improves the development efficiency.
Quote the commonly used method 1 of Moment.jsnpm install moment, moment ()
Get the current date and time
Moment ()
Get the date and time of the String
Moment (String) 2. Get get
Get the year of the day
Moment () .get ('year')
Get the month 0-11 of the day
Moment () .get ('month')
Get the date of the day
Moment () .get ('date') 3, format format
The resulting time format is YYYY-MM-DD
Moment (String,'YYYY-MM-DD') moment (String) .format ('YYYY-MM-DD') 4, set subtract
.subtract (Number, String)
Set the year, get the time of one year ago
Moment () .subtract (1 'years')
Set the month to get the time of one month ago
Moment () .subtract (1 'months')
Set the date to get the time of yesterday
Moment () .subtract (1, 'days') 5, start startOf ()
Change the original moment by setting it to the beginning of the time unit.
.startOf (String)
Get today's 00:00:00
Moment () .startOf ('day')
Get 00:00:00 on the first day of the week
Moment () .startOf ('week') 6, end endOf ()
Change the original moment by setting it to the end of the time unit
.endOf (String)
Get today's 23:59:59
Moment () .endOf ('day')
Get 23:59:59 on the first day of the week
Moment () .endOf ('week') 7, total days Days in Month
.daysInMonth ()
Gets the number of days in February.
Moment ("2012-02", "YYYY-MM"). DaysInMonth () / / 298, timestamp
.unix () / / seconds
.valueof () / / milliseconds
Get timestamp (in seconds)
Moment (). Format ('X'). Unix () / the return value is numeric
Get timestamp (in milliseconds)
Moment (). Format ('x'). ValueOf () / / the return value is numeric 9, the actual combat on the ant selection time
The disabledDate use of the a-range-picker component of ant
You cannot choose a date before today (including today)
DisabledDate (current) {return current & & current < moment () .endOf ('day');}
You cannot choose a date before today (excluding today)
DisabledDate (current) {return current & & current < moment (). Subtract (1, 'days'). EndOf (' day')}
Click on the selected data before 2019-01-01 cannot be confirmed.
DisabledDate (current) {return current & & current < moment ('2019-01-01')}, that's all for the analysis of examples of common uses of Moment.js. Thank you for reading. If you want to know more about the industry, you can follow the industry information channel. The editor will update different knowledge points for you every day.
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.