当前位置:网站首页>moment的使用
moment的使用
2022-08-05 07:04:00 【good法乐】
import moment from 'moment';
moment().format('YYYY-MM-DD'); // 2019-04-27
moment().format('YYYY.MM.DD hh:mm:ss'); // 2019.04.27 11:08:53
moment().format('YYYY年MM月DD日 hh:mm:ss') // 2019年04月27日 11:08:53
moment().format('HH时mm分ss秒') //24小时制 'xx时xx分xx秒'
moment().format('hh:mm:ss a') // 12小时制'xx:xx:xx am/pm'
moment(时间戳).format("YYYY-MM-DD") //输出实例 如 2019-04-27
moment().year(); // 2019
moment().month() + 1; // 4
moment().date(); // 27
moment().hour(); // 23
moment().minute(); // 12
moment().second(); // 14
moment().millisecond(); // 188,毫秒复制代码
获取时间戳(当前时间转时间戳)
moment().format('X') // (大写X)以秒为单位,返回值为字符串类型
moment().format('x') // (小写x)以毫秒为单位,返回值为字符串类型
moment().valueOf() // 以毫秒为单位,返回值为数值型
获取当前的年月日时分秒—数组或对象
moment().toArray() // [years, months, date, hours, minutes, seconds, milliseconds]
moment().toObject() // {years: xxxx, months: x, date: xx ...}
startOf()和endOf
moment().startOf('day') //获取今天0时0分0秒
moment().startOf('week') //获取本周第一天(周日)0时0分0秒
moment().startOf('isoWeek') //获取本周周一0时0分0秒
moment().startOf('month') //获取当前月第一天0时0分0秒
moment().endOf('day') //获取今天23时59分59秒
moment().endOf('week') //获取本周最后一天(周六)23时59分59秒
moment().endOf('isoWeek') //获取本周周日23时59分59秒
moment().endOf('month') 获取当前月最后一天23时59分59秒
获取当前时间的周一和周日的日期
moment().day(1)
moment().day(7)
获取上个月的第一天和未来一个月的最后一天
var prevMonthFirstDay = new moment().subtract(1,’months’).date(1)
var nextMonthLastDay = new moment().add(2,'months').date(0)
默认最近一个月
time: [moment().subtract(1, 'months').format('YYYY-MM-DD HH:mm:ss'), moment().format('YYYY-MM-DD HH:mm:ss')]
边栏推荐
- 腾讯实习总结
- 2006年星座运势全解-巨蟹
- DeFi 前景展望:概览主流 DeFi 协议二季度进展
- After working for 3 years, I recalled the comparison between the past and the present when I first started, and joked about my testing career
- Redis 全套学习笔记.pdf,太全了
- 400 times performance improvement 丨 swap valuation optimization case calculation
- 一天学会从抓包到接口测试,通过智慧物业项目深度解析
- MAYA船的建模
- Falsely bamboo brother today and found a localization of API to use tools
- Technical Analysis Mode (8) Double Top and Bottom
猜你喜欢

不太会讲爱,其实已经偷偷幸福很久啦----我们的故事

DNSlog外带数据注入

Flink学习11:flink程序并行度

MySQL: order by sorting query, group by grouping query

After working for 3 years, I recalled the comparison between the past and the present when I first started, and joked about my testing career

MAYA船的建模

Re regular expressions

Falsely bamboo brother today and found a localization of API to use tools

U++ UE4官方文档课后作业

ARM Cortex-M上的Trace跟踪方案
随机推荐
Technical Analysis Patterns (11) How to Trade Head and Shoulders Patterns
Shiny04---Application of DT and progress bar in shiny
GAN生成动漫头像Pytorch
mysql使用in函数的一个小问题
Hash 这些知识你也应该知道
Advanced Redis
Flink学习11:flink程序并行度
Flink学习10:使用idea编写WordCount,并打包运行
An IP conflict is reported after installing the software on a dedicated computer terminal
Flink学习12:DataStreaming API
【 LeetCode 】 235. A binary search tree in recent common ancestor
Technical Analysis Mode (7) Playing the Gap
线程池的创建及参数设置详解
After working for 3 years, I recalled the comparison between the past and the present when I first started, and joked about my testing career
Summary of Text Characterization Methods
2006年星座运势全解-射手
蓝牙gap协议
RK3568环境安装
[instancetype type Objective-C]
Mysql主从延迟的原因和解决方案