当前位置:网站首页>時間格式化工具----moment.js(網頁時間實時展示)
時間格式化工具----moment.js(網頁時間實時展示)
2022-06-13 06:35:00 【逆風優雅】
moment.js官方網站:Moment.js 中文網
一 、 安裝方式(常用)
yarn add moment
npm i moment --save
二 、 使用
日期格式化:
moment().format('MMMM Do YYYY, h:mm:ss a'); // 五月 28日 2022, 2:54:47 下午
moment().format('dddd'); // 星期六
moment().format("MMM Do YY"); // 5月 28日 22
moment().format('YYYY [至] YYYY'); // 2022 至2022
moment().format(); // 2022-05-28T14:54:47+08:00
相對時間:
moment("20111031", "YYYYMMDD").fromNow(); // 11 年前
moment("20120620", "YYYYMMDD").fromNow(); // 10 年前
moment().startOf('day').fromNow(); // 15 小時前
moment().endOf('day').fromNow(); // 9 小時內
moment().startOf('hour').fromNow(); // 1 小時前
日曆時間:
moment().subtract(10, 'days').calendar(); // 2022/05/18
moment().subtract(6, 'days').calendar(); // 上星期日14:54
moment().subtract(3, 'days').calendar(); // 上星期三14:54
moment().subtract(1, 'days').calendar(); // 昨天14:54
moment().calendar(); // 今天14:54
moment().add(1, 'days').calendar(); // 明天14:54
moment().add(3, 'days').calendar(); // 下星期二14:54
moment().add(10, 'days').calendar(); // 2022/06/07
渲染年月日:
moment().format("YYYY-MM-DD") // 2022-05-28
渲染時分秒
moment().format("HH:mm:ss") // 15:00
實現實時時間展示的方式 (做一個間隙性計時器,每隔1秒鐘調用一次):
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);
边栏推荐
- Echart histogram: stack histogram value formatted display
- Differences among concurrent, parallel, serial, synchronous and asynchronous
- ‘ipconfig‘ 不是内部或外部命令,也不是可运行的程序 或批处理文件。
- 'ipconfig' is not an internal or external command, nor is it a runnable program or batch file.
- MFS explanation (VI) -- MFS chunk server installation and configuration
- Thread correlation point
- MFS详解(七)——MFS客户端与web监控安装配置
- IOError(Errors.E050.format(name=name))
- Use of kotlin basic common sets list, set and map
- Applet pull-up loading data
猜你喜欢
In kotlin?,!,?:,:, - & gt;、== Brief description of symbols
Vector control of Brushless DC motor (4): sensorless control based on sliding mode observer
Intelligent digital asset management helps enterprises win the post epidemic Era
SSM框架整合--->简单后台管理
MFS explanation (V) -- MFS metadata log server installation and configuration
The boys x pubgmobile linkage is coming! Check out the latest game posters
JVM Foundation
Detailed explanation of PHP distributed transaction principle
Echart histogram: stack histogram value formatted display
[FAQs for novices on the road] about technology management
随机推荐
Kotlin collaboration - start and cancel, scope
Applet pull-up loading data
App performance test: (III) traffic monitoring
Comprehensive overview of ijkplayer contour features for ijkplayer code walk through
电镀挂具RFID工序管理解决方案
Subtotal of constraintlayout
Kotlin basic objects, classes and interfaces
【Kernel】驱动编译的两种方式:编译成模块、编译进内核(使用杂项设备驱动模板)
Notifyitemchanged flash back
【js】var、let、const
Ijkplayer code walkthrough player network video data reading process details
[FAQs for novices on the road] about technology management
Wechat applet (function transfer parameters, transfer multiple parameters, page Jump)
The boys x pubgmobile linkage is coming! Check out the latest game posters
Simple use of event bus
Dynamic link library nesting example
Wechat applet: click the event to obtain the current device information (basic)
Super model logo online design and production tool
JNI exception handling
时间格式化工具----moment.js(网页时间实时展示)