代码拉取完成,页面将自动刷新
极简的日期时间处理库
new Dates().format(); // 2023-05-06 15:27:50
new Dates(1683422870000).format(); // 2023-05-06 15:27:50
new Dates(1683422870000).format('YY-MM-DD'); // 23-05-06
// 日期比较
new Dates().diffWith('2023-5-8 18:00:00')
// 结果 { "date": 0, "hour": 2, "minutes": 0, "second": 0, "millisecond": 0, "offset": -7200000 }
new Dates('2023-5-8 16:00:00').diffWith('2023-5-8 18:00:00')
// 结果 { "date": 0, "hour": 2, "minutes": 0, "second": 0, "millisecond": 0, "offset": -7200000 }
// 往后推2天
new Dates().days(-2).format() // 2023-05-04 15:27:50
// 往后推2分钟
new Dates().minutes(-2).format() // 2023-05-04 15:25:50
// 转为北京时间
new Dates().toBeijing().format() // 2023-05-06 15:27:50
// 转为指定时区的时间(如北京时间,则传入8)
new Dates(1683422870000).setUTC(-1).format() // 2023-05-07 00:27:50
api | 参数 | 说明 | 默认值 |
---|---|---|---|
构造函数 | value | [非必传][string 、number],可传入时间戳(毫秒)或 字符串时间日期 | 本地时间 |
format | value | [非必传] 时间格式化 | 'YYYY-MM-DD hh:mm:ss' |
diffWith | value,unitType | value[必传],将要比较的目标日期时间;unitType [非必传], 比较结果的类型,可传入date、hour、minutes、second、millisecond,不传默认返回Object: {date:天,hour:时,minutes:分,second:秒,millisecond:毫秒, offset: 时间戳差值} | - |
days | value | [非必传] 偏移天数 | - |
minutes | value | [非必传] 偏移分钟数 | - |
toBeijing | - | 转换为北京时间 | - |
setUTC | value | [必传] 转换时间时区,比如,北京(东8区),传入8;夏威夷(西10区),传入 -10。时区查询地址:https://www.beijing-time.org/shiqu/ | - |
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。