当前位置:网站首页>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')]
边栏推荐
- (4) Rotating object detection data roLabelImg to DOTA format
- Using printf function in STM32
- An IP conflict is reported after installing the software on a dedicated computer terminal
- [instancetype type Objective-C]
- Modeling of the MAYA ship
- RK3568环境安装
- 【动态类型检测 Objective-C】
- 任务流调度工具AirFlow,,220804,,
- PCI Pharma Services Announces Multi-Million Dollar Expansion of UK Manufacturing Facility to Meet Growing Demand for Global High Potency Drug Manufacturing Services to Support Oncology Treatment
- MAYA船的建模
猜你喜欢
随机推荐
re正则表达式
Shiny04---DT和进度条在shiny中的应用
HR:这样的简历我只看了5秒就扔了,软件测试简历模板想要的进。
TRACE32——List源代码查看
DeFi 前景展望:概览主流 DeFi 协议二季度进展
一天学会从抓包到接口测试,通过智慧物业项目深度解析
MySQL: JDBC programming
Flink学习10:使用idea编写WordCount,并打包运行
RNote108---Display the running progress of the R program
Cannot compare or sort text, ntext, and image data types
软件测试必问面试题(附答案和解析)
How to avoid online memory leaks
2022 Fusion Welding and Thermal Cutting Operation Certificate Exam Questions and Mock Exams
不太会讲爱,其实已经偷偷幸福很久啦----我们的故事
binary search tree problem
二叉搜索树问题
[Shanghai] Hiring .Net Senior Software Engineer & BI Data Warehouse Engineer (Urgent)
A small problem with mysql using the in function
【LeetCode】235.二叉搜索树的最近公共祖先
开启防火墙iptable规则后,系统网络变慢