当前位置:网站首页>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')]
边栏推荐
- GAN generates anime avatar Pytorch
- HR:这样的简历我只看了5秒就扔了,软件测试简历模板想要的进。
- Modeling of the MAYA ship
- In the anaconda Promat interface, import torch is passed, and the error is reported in the jupyter notebook (only provide ideas and understanding!)
- 女生做软件测试会不会成为一个趋势?
- 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
- 【Dynamic type detection Objective-C】
- 文本特征化方法总结
- Vulnhub靶机:HA_ NARAK
- 691. 立方体IV
猜你喜欢

AI + video technology helps to ensure campus security, how to build a campus intelligent security platform?

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

cmake 学习使用笔记(三)

TCP的粘包拆包问题+解决方案

Hash these knowledge you should also know

Put Cloudflare on the website (take Tencent Cloud as an example)

Redis数据库学习

Vulnhub靶机:HA_ NARAK

re正则表达式

RNote108---Display the running progress of the R program
随机推荐
4520. 质数
691. 立方体IV
protobuf is compiled against the associated .proto file
693. 行程排序
Database table insert data
专用机终端安装软件后报IP冲突
TRACE32——通用寄存器查看与修改
Put Cloudflare on the website (take Tencent Cloud as an example)
Technical Analysis Mode (7) Playing the Gap
Game Thinking 19: Multi-dimensional calculation related to games: point product, cross product, point-line-surface distance calculation
Task flow scheduling tool AirFlow,, 220804,,
Shiny04---Application of DT and progress bar in shiny
TRACE32——List源代码查看
真实字节跳动测试开发面试题,拿下年薪50万offer。
Shiny04---DT和进度条在shiny中的应用
Illegal key size 报错问题
[Shanghai] Hiring .Net Senior Software Engineer & BI Data Warehouse Engineer (Urgent)
MySQL:连接查询 | 内连接,外连接
HR:这样的简历我只看了5秒就扔了,软件测试简历模板想要的进。
Summary of Text Characterization Methods