Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

What are the time functions in nodejs

2025-01-21 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/02 Report--

The editor will share with you what the time functions are in nodejs. I hope you will get something after reading this article. Let's discuss it together.

Time function in nodejs: 1, moment (); 2, format (); 3, diff (); 4, startOf (); 5, endOf (); 6, add (); 7, subtract (); 8, dayjs (); 9, year (); 10, toDate (), and so on.

This tutorial operating environment: windows7 system, nodejs version 12.19.0, DELL G3 computer.

The moment time function applies / / format time moment ('2017-09-01'). Format ('YYYYMMDD') / / current time moment (). Format (' YYYY-MM-DD HH:mm:ss'); / / current time now = moment (); / / format end time endMoment = moment (endDate, 'YYYYMM') / / the interval between the end time and the current time now.diff (endMoment, 'months') / / the previous week startDate = moment (now.join (''), 'YYYYw'). StartOf (' week'). Add (1, 'day'). Format (' YYYY-MM-DD 00 day' 00') EndDate = moment (now.join (''), 'YYYYw'). EndOf (' week'). Add (1, 'day'). Format (' YYYY-MM-DD 23 lastStartDate 59)); / / lastStartDate = moment (now.join (''), 'YYYYw'). Subtract (1,' week'). StartOf ('week'). Add (1,' day'). Format LastEndDate = moment (now.join (''), 'YYYYw'). Subtract (1,' week'). EndOf ('week'). Add (1,' day'). Format ('YYYY-MM-DD 23 day' 59'); / / the previous month startDate = moment (now.join (''), 'YYYYMM'). StartOf (' month'). Format ('YYYY-MM-DD 0000vvvv0000') EndDate = moment (now.join (''), 'YYYYMM'). EndOf (' month'). Format ('YYYY-MM-DD 23 YYYYMM' 59'); / / lastStartDate = moment (now.join (''), 'YYYYMM'). Subtract (1,' month'). StartOf ('month'). Format LastEndDate = moment (now.join (''), 'YYYYMM'). Subtract (1,' month'). EndOf ('month'). Format (' YYYY-MM-DD 23 subtract 59)); / / the start date of the year const startYear = dayjs (). StartOf ('year'); / / the end date of the year const endYear = dayjs (). EndOf (' year'); / / current time const current = dayjs (). StartOf ('day') / / how many days have elapsed in a year other than today const yearStartDay = current.diff (dayjs (). StartOf ('year'), "day"); / / how many days remain in a year const yearEndDay = dayjs (). EndOf (' year') .diff (current, "day"); dayjs time function applies the current time const current = dayjs (); / / current year return dayjs (). Year (); format () returns the formatted date based on the passed placeholder. Dayjs ('2019-01-25'). Format ('DD/MM/YYYY') / /' 25/01/2019'dayjs ('2019-01-25'). Format ('YYYY-MM-DD HH:mm:ss') / /' 2019-01-25 0000 DD01 00' logo example describes the YY18 year, two-digit YYYY2018 year, four-digit M1-December, from 1 to December, two-digit MMMJan-Dec month, abbreviation D1-31 DD01-31 Double-digit H0-2324 hours HH00-2324 hours, double-digit H1-1212 hours hh01-1212 hours, double-digit M0-59 minutes mm00-59 minutes, double-digit S0-59 seconds ss00-59 seconds, double-digit S0-9 milliseconds (100), one-digit SS00-99ms (ten), double-digit SSS000-99ms, three-digit Z-05:00UTC offset ZZ-0500UTC offset, double-digit AAM / PM morning / afternoon, uppercase aam / pm morning / afternoon, lowercase Do1st … The date and serial number of 31st month startOf () sets the beginning of a time, and endOf () sets the end of a time.

/ / set the start of a time dayjs (). StartOf ('year'); / / set the end of a time dayjs (). EndOf (' month') unit abbreviation details yeary on January 1 this year morning 00:00quarterQ the first month of the quarter at 00:00 on the 1st (relying on the QuarterOfYear plug-in) monthM on the 1st of this month 00:00weekw the first day of the week in the morning 00:00isoWeek

The first day of the week at 00:00 (according to ISO 8601) (depending on the IsoWeek plug-in) dateD current time of the day 00:00dayd that day 00:00hourh current time, 0 minutes, 0 seconds, 0 milliseconds minutem current time, 0 seconds, 0 milliseconds seconds current time 0 millisecond Add () increases time / / increases seven days dayjs (). Add (7, 'day') / / minus dayjs (). Subtract (7,' year') subtract () reduces time dayjs (). Subtract (1, 'day') ToDate () returns the original time object dayjs (). ToDate (); after reading this article, I believe you have a certain understanding of "what are the time functions in nodejs". If you want to know more about it, welcome to follow the industry information channel, thank you for reading!

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.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report