1.0.5 • Published 2 years ago

past-time v1.0.5

Weekly downloads
-
License
MIT
Repository
-
Last release
2 years ago

past-time

介绍

日期时间的中文表达

使用

const pastTime = require('past-time')

let date = new Date()
date.setMinutes(10)
date.setSeconds(2)
for (let i = 0; i < 12; i++) {
    let t1 = pastTime(date, {awaysShort: false, format: 'YYYY-MM-DD hh:mm:ss'})
    let t2 = pastTime(date, {awaysShort: true, format: 'YYYY-MM-DD hh:mm:ss'})
    console.log(t1, '====', t2)
    date.setDate(date.getDate() + 1)
}

输出结果

2021-04-01 15:10:02 ==== 17分钟前
2021-04-02 15:10:02 ==== 明天 15:10
2021-04-03 15:10:02 ==== 后天 15:10
2021-04-04 15:10:02 ==== 大后天 15:10
2021-04-05 15:10:02 ==== 下周一 15:10
2021-04-06 15:10:02 ==== 下周二 15:10
2021-04-07 15:10:02 ==== 下周三 15:10
2021-04-08 15:10:02 ==== 下周四 15:10
2021-04-09 15:10:02 ==== 下周五 15:10
2021-04-10 15:10:02 ==== 下周六 15:10
2021-04-11 15:10:02 ==== 下周日 15:10
2021-04-12 15:10:02 ==== 2021-04-12 15:10:02
console.log('日期字符串 2021-03-19T07:55:26.355Z')
console.log(pastTime('2021-03-19T07:55:26.355Z'))
console.log(pastTime.date2json(new Date()))
// 输出结果
'日期字符串 2021-03-19T07:55:26.355Z'
'2021/03/19 15:55'
{
  year: 2021,
  month: 11,
  day: 19,
  hour: 11,
  minute: 19,
  second: 11,
  week: 5,
  a: '上午',
  hour12: 11
}

示例展示

alt 属性文本

1.0.5

2 years ago

1.0.4

2 years ago

1.0.3

3 years ago

1.0.2

3 years ago

1.0.1

3 years ago

1.0.0

3 years ago