当前位置:网站首页>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')]
边栏推荐
- Redis
- 【网友真实投稿】为女友放弃国企舒适圈,转行软件测试12k*13薪
- Mysql主从延迟的原因和解决方案
- Shiny04---DT和进度条在shiny中的应用
- protobuf根据有关联的.proto文件进行编译
- Why does Mysql fail to create a database
- Shiny04---Application of DT and progress bar in shiny
- TRACE32——通用寄存器查看与修改
- 线程池的创建及参数设置详解
- "Automatic Data Collection Based on R Language"--Chapter 3 XML and JSON
猜你喜欢

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

【 LeetCode 】 235. A binary search tree in recent common ancestor

Re regular expressions

protobuf is compiled against the associated .proto file

MySQL:连接查询 | 内连接,外连接

(4) Rotating object detection data roLabelImg to DOTA format

Flink学习10:使用idea编写WordCount,并打包运行

HR:这样的简历我只看了5秒就扔了,软件测试简历模板想要的进。

Redis数据库学习

TCP sticky packet unpacking problem + solution
随机推荐
标准C语言15
对数据类型而言运算符无效。运算符为 add,类型为 text。
Libpq 是否支持读写分离配置
AI+视频技术助力保障校园安全,校园智能安防平台该如何建设?
LaTeX Notes
binary search tree problem
Task flow scheduling tool AirFlow,, 220804,,
Re regular expressions
【JVM调优】Xms和Xmx为什么要保持一致
Flink学习10:使用idea编写WordCount,并打包运行
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
专用机终端安装软件后报IP冲突
MySQL: JDBC programming
IO process thread -> communication between processes -> day7
环网冗余式CAN/光纤转换器 CAN总线转光纤转换器中继集线器hub光端机
Modeling of the MAYA ship
Flink学习11:flink程序并行度
任务流调度工具AirFlow,,220804,,
高端无主灯设计灯光设计该如何布置射灯灯具?
2022.7.29好题选讲(计数专题)