当前位置:网站首页>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);
边栏推荐
- 《MATLAB 神经网络43个案例分析》:第10章 离散Hopfield神经网络的分类——高校科研能力评价
- JVM Foundation
- PHP redis makes high burst spike
- [virtual machine] VMware virtual machine occupies too much space. Solution
- Wechat applet: basic review
- [2022 college entrance examination season] what I want to say as a passer-by
- Intelligent digital asset management helps enterprises win the post epidemic Era
- RN Metro packaging process and sentry code monitoring
- Simple use of event bus
- [JS] handwriting call(), apply(), bind()
猜你喜欢
Notes on wechat applet development
无刷直流电机矢量控制(四):基于滑模观测器的无传感器控制
Analysis of 43 cases of MATLAB neural network: Chapter 11 optimization of continuous Hopfield Neural Network -- optimization calculation of traveling salesman problem
【sketchup 2021】草图大师的图像输出与渲染之样式说明【边线设置、平面设置、背景设置、水印设置、建模设置、天空背景创建天空、利用水印背景创建天空(重要)】
In kotlin?,!,?:,:, - & gt;、== Brief description of symbols
Construction and verification of Alibaba cloud server webrtc system
Kotlin collaboration -- context and exception handling
MFS explanation (V) -- MFS metadata log server installation and configuration
JVM Foundation
Jetpack - basic use of room
随机推荐
线程相关点
[solution] camunda deployment process should point to a running platform rest API
Common websites and tools
347. top k high frequency elements heap sort + bucket sort +map
Ijkplayer code walk through read_ AV in thread thread_ read_ Detailed explanation of frame() data stream reading process
SSM framework integration -- > simple background management
Notes on wechat applet development
Use of kotlin basic common sets list, set and map
【新手上路常见问答】关于技术管理
ADB shell content command debug database
Wechat applet: use of global state variables
Introduction to applet layout
After clicking the uniapp e-commerce H5 embedded applet, the page prompts "the page iframe does not support referencing non business domain names"
The web server failed to start Port 7001 was already in use
Kotlin basic string operation, numeric type conversion and standard library functions
[2022 college entrance examination season] what I want to say as a passer-by
AI realizes "Resurrection" of relatives | old photo repair | old photo coloring, recommended by free app
Command line for database
JS convert text to language for playback
Using the shutter floor database framework