当前位置:网站首页>Time formatting tool ----moment JS (real time display of web page time)
Time formatting tool ----moment JS (real time display of web page time)
2022-06-13 06:36:00 【Upwind elegance】
moment.js Official website :Moment.js Chinese net
One 、 Installation mode ( Commonly used )
yarn add moment
npm i moment --save
Two 、 Use
Date formatting :
moment().format('MMMM Do YYYY, h:mm:ss a'); // May 28 Japan 2022, 2:54:47 Afternoon
moment().format('dddd'); // Saturday
moment().format("MMM Do YY"); // 5 month 28 Japan 22
moment().format('YYYY [ to ] YYYY'); // 2022 to 2022
moment().format(); // 2022-05-28T14:54:47+08:00
Relative time :
moment("20111031", "YYYYMMDD").fromNow(); // 11 Years ago
moment("20120620", "YYYYMMDD").fromNow(); // 10 Years ago
moment().startOf('day').fromNow(); // 15 Hours before
moment().endOf('day').fromNow(); // 9 Within hours
moment().startOf('hour').fromNow(); // 1 Hours before
Calendar time :
moment().subtract(10, 'days').calendar(); // 2022/05/18
moment().subtract(6, 'days').calendar(); // Last Sunday 14:54
moment().subtract(3, 'days').calendar(); // Last Wednesday 14:54
moment().subtract(1, 'days').calendar(); // yesterday 14:54
moment().calendar(); // today 14:54
moment().add(1, 'days').calendar(); // Tomorrow, 14:54
moment().add(3, 'days').calendar(); // Next Tuesday 14:54
moment().add(10, 'days').calendar(); // 2022/06/07
Render date :
moment().format("YYYY-MM-DD") // 2022-05-28
Rendering time: minutes and seconds
moment().format("HH:mm:ss") // 15:00
Realization Real time Way of presentation ( Make a gap timer , every other 1 Call once per second ):
this.nowDate = moment().format("YYYY-MM-DD");
this.nowTime = moment().format("HH:mm:ss");
this.timeF = setInterval(()=>{
this.nowDate = moment().format("YYYY-MM-DD");
this.nowTime = moment().format("HH:mm:ss");
}, 1000);
边栏推荐
- JVM基础
- 《MATLAB 神经网络43个案例分析》:第10章 离散Hopfield神经网络的分类——高校科研能力评价
- Detailed explanation of scrcpy client code walk through H264 raw stream decoding process
- Detailed explanation of Yanghui triangle
- Intelligent digital asset management helps enterprises win the post epidemic Era
- ‘ipconfig‘ 不是内部或外部命令,也不是可运行的程序 或批处理文件。
- JetPack - - - LifeCycle、ViewModel、LiveData
- Hidden and wx:if
- Analysis of 43 cases of MATLAB neural network: Chapter 10 classification of discrete Hopfield Neural Network -- evaluation of scientific research ability of colleges and Universities
- Wechat applet: use of global state variables
猜你喜欢
[one · data 𞓜 simple implementation of the leading two-way circular linked list]
JetPack - - - LifeCycle、ViewModel、LiveData
Analysis of 43 cases of MATLAB neural network: Chapter 11 optimization of continuous Hopfield Neural Network -- optimization calculation of traveling salesman problem
Intelligent digital asset management helps enterprises win the post epidemic Era
You should consider upgrading via
机器学习笔记 - 监督学习备忘清单
Dart class inherits and implements mixed operators
Wechat applet: click the event to obtain the current device information (basic)
楊輝三角形詳解
MFS explanation (VI) -- MFS chunk server installation and configuration
随机推荐
Vector control of Brushless DC motor (4): sensorless control based on sliding mode observer
Using the shutter floor database framework
Differences among concurrent, parallel, serial, synchronous and asynchronous
PHP redis makes high burst spike
Hidden and wx:if
JS to realize bidirectional data binding
Detailed explanation of PHP distributed transaction principle
[written examination questions of meituan]
【sketchup 2021】草图大师的图像输出与渲染之样式说明【边线设置、平面设置、背景设置、水印设置、建模设置、天空背景创建天空、利用水印背景创建天空(重要)】
端午安康,使用祝福话语生成词云吧
Unable to locate program input point getrawinputdevicelist in dynamic link library user32 DLL processing
[JS] array de duplication
Win10 drqa installation
[MySQL] basic knowledge review
[one · data 𞓜 simple implementation of the leading two-way circular linked list]
[virtual machine] VMware virtual machine occupies too much space. Solution
c语言对文件相关的处理和应用
Using async await in applets
Analysis of synchronized
Applet disable native top