当前位置:网站首页>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')]
边栏推荐
- TRACE32——C源码关联1
- 给网站套上Cloudflare(以腾讯云为例)
- Tencent Internship Summary
- Technical Analysis Mode (7) Playing the Gap
- protobuf is compiled against the associated .proto file
- 腾讯实习总结
- Task flow scheduling tool AirFlow,, 220804,,
- Algorithm Supplements Fifteen Complementary Linked List Related Interview Questions
- Illegal key size 报错问题
- 风控特征的优化分箱,看看这样教科书的操作
猜你喜欢

Flink Learning 12: DataStreaming API

cmake 学习使用笔记(三)

DeFi 前景展望:概览主流 DeFi 协议二季度进展

Game Thinking 19: Multi-dimensional calculation related to games: point product, cross product, point-line-surface distance calculation

真实字节跳动测试开发面试题,拿下年薪50万offer。

Vulnhub靶机:HA_ NARAK

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

IO process thread -> communication between processes -> day7

MySQL: join query | inner join, outer join

MySQL: JDBC programming
随机推荐
二叉搜索树问题
protobuf根据有关联的.proto文件进行编译
RK3568 environment installation
Bluetooth gap protocol
HR:这样的简历我只看了5秒就扔了,软件测试简历模板想要的进。
基于KECA-IGWO-KELM的间歇过程故障诊断方法
U++ UE4官方文档课后作业
2022 crane driver (limited bridge crane) exam question bank and simulation test
不能比较或排序 text、ntext 和 image 数据类型
对数据类型而言运算符无效。运算符为 add,类型为 text。
GAN generates anime avatar Pytorch
After the firewall iptable rule is enabled, the system network becomes slow
Redis
Technical Analysis Patterns (11) How to Trade Head and Shoulders Patterns
C# FileSystemWatcher
Discourse 清理存储空间的方法
RNote108---显示R程序的运行进度
2022 Fusion Welding and Thermal Cutting Operation Certificate Exam Questions and Mock Exams
Week 8 Document Clustering
AI + video technology helps to ensure campus security, how to build a campus intelligent security platform?