当前位置:网站首页>時間格式化工具----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);边栏推荐
- 'ipconfig' is not an internal or external command, nor is it a runnable program or batch file.
- RN Metro packaging process and sentry code monitoring
- High burst solution 2
- Relationship between fragment lifecycle and activity
- SSM框架整合--->简单后台管理
- 电镀挂具RFID工序管理解决方案
- The processing and application of C language to documents
- Recent problems
- synchronized浅析
- JetPack - - -WorkManger
猜你喜欢

MFS详解(六)——MFS Chunk Server服务器安装与配置

‘ipconfig‘ 不是内部或外部命令,也不是可运行的程序 或批处理文件。

SSM framework integration -- > simple background management

Echart histogram: stack histogram value formatted display

Analysis of 43 cases of MATLAB neural network: Chapter 11 optimization of continuous Hopfield Neural Network -- optimization calculation of traveling salesman problem

Wechat applet (get location)

MFS details (vii) - - MFS client and Web Monitoring installation configuration

Super model logo online design and production tool
![[FAQs for novices on the road] about technology management](/img/6f/cb2152d5ddb4714e1b249e50096947.jpg)
[FAQs for novices on the road] about technology management

MFS詳解(七)——MFS客戶端與web監控安裝配置
随机推荐
Wechat applet custom tabbar (session customer service) vant
'ipconfig' is not an internal or external command, nor is it a runnable program or batch file.
Explication détaillée du triangle Yang hui
MFS详解(五)——MFS元数据日志服务器安装与配置
App performance test: (III) traffic monitoring
Kotlin foundation extension
Kotlin collaboration process +flow download case
c语言对文件相关的处理和应用
Dynamic link library nesting example
Detailed explanation of scrcpy client code walk through H264 raw stream decoding process
机器学习笔记 - 监督学习备忘清单
电镀挂具RFID工序管理解决方案
Use of kotlin basic common sets list, set and map
The boys x pubgmobile linkage is coming! Check out the latest game posters
Differences among concurrent, parallel, serial, synchronous and asynchronous
端午安康,使用祝福话语生成词云吧
SSM框架整合--->简单后台管理
MFS details (VII) -- MFS client and web monitoring installation configuration
Kotlin data flow - flow
Wechat applet development (requesting background data and encapsulating request function)