All Projects → pengng → time-formater

pengng / time-formater

Licence: other
在javascript中显示日期。

Programming Languages

javascript
184084 projects - #8 most used programming language

Projects that are alternatives of or similar to time-formater

popoPicker
popoPicker是一个移动端3D滚轮日期时间和单项的选择器,支持无限循环滚动,不依赖第三方库
Stars: ✭ 26 (-40.91%)
Mutual labels:  time, date
dt
Go's missing DateTime package
Stars: ✭ 34 (-22.73%)
Mutual labels:  time, date
island-time
A Kotlin Multiplatform library for working with dates and times
Stars: ✭ 69 (+56.82%)
Mutual labels:  time, date
kronos
Management of arithmetic operations on dates
Stars: ✭ 23 (-47.73%)
Mutual labels:  time, date
vue-translated
Internationalization (i18n) and localization (l10n) library for Vue.js v2.
Stars: ✭ 19 (-56.82%)
Mutual labels:  time, date
TimesDates.jl
Nanosecond resolution for Time and Date, TimeZones
Stars: ✭ 28 (-36.36%)
Mutual labels:  time, date
qrono
🕥 Just right date time library
Stars: ✭ 111 (+152.27%)
Mutual labels:  time, date
timelite
String date and time utilities 🕙
Stars: ✭ 17 (-61.36%)
Mutual labels:  time, date
relative.time.parser
Moment.js Plugin for parsing Relative Time Strings
Stars: ✭ 13 (-70.45%)
Mutual labels:  time, date
tir
Have time.ir in shell!
Stars: ✭ 114 (+159.09%)
Mutual labels:  time, date
hs-hourglass
efficient and simpler time API for haskell
Stars: ✭ 43 (-2.27%)
Mutual labels:  time, date
ElevenClock
ElevenClock: Customize Windows 11 taskbar clock
Stars: ✭ 1,494 (+3295.45%)
Mutual labels:  time, date
time machine
A date and time API for Dart
Stars: ✭ 120 (+172.73%)
Mutual labels:  time, date
go-systemd-time
📅 Go implementation of systemd relative time adjustments
Stars: ✭ 21 (-52.27%)
Mutual labels:  time, date
temps-lite
A smart, good-looking little app which tries to speak your language the way you are used to.
Stars: ✭ 40 (-9.09%)
Mutual labels:  time, date
rutimeparser
Recognize date and time in russian text and return datetime.datetime.
Stars: ✭ 17 (-61.36%)
Mutual labels:  time, date
date-extractor
Extract dates from text
Stars: ✭ 58 (+31.82%)
Mutual labels:  time, date
duration
Parse iso8601 duration strings, and use to shift dates/times.
Stars: ✭ 51 (+15.91%)
Mutual labels:  time, date
FM-JSON-Types
FileMaker Data Types in JSON
Stars: ✭ 14 (-68.18%)
Mutual labels:  time, date
silverware-calendar
SilverWare Calendar Module
Stars: ✭ 15 (-65.91%)
Mutual labels:  time, date

time-formater

不是 time-format[t]er

English

在javascript中显示日期。

使用方法

npm i -S time-formater
const time = require('time-formater')

let rawDate = time().format('YYYY-MM-DD HH:mm:ss') // 当前时间
console.log(rawDate) // 2017-05-21 15:19:34

解析

  • 当前时间
let now = time()

如果参数为空则获取当前系统时间。

  • 数字
let date = time(1495355143424)

如果传入参数为数字,则表示UTC时间戳。

  • 字符串
let date = time('2017-05-21')
// or
let date = time('2017-05-21 16:37:02')
// or
let date = time('2017-05-21 13:20:35+0800')
// or
let date = time('2017-05-21 19:02:59-08:00')
// or
let date = time('2017-05-21 12:38:49Z')

如果传入字符串,则必须符合ISO 8601格式。

  • 原生日期对象
let date = time(new Date())

传入参数也可以是一个原生的javascript日期对象。

显示

format(string)

let rawDate = time().format('YYYY-MM-DD') // 2017-05-21

特定字符串所代表的含义

Token Output
月份 M 1 2 ... 11 12
MM 01 02 ... 11 12
MMM 1月 2月 ... 11月 12月
MMMM 一月 二月 ... 十二月
季度 Q 1 2 3 4
日期 D 1 2 ... 30 31
Do 1日 2日 ... 30日 31日
DD 01 02 ... 30 31
星期 d 0 1 2 3 4 5 6
dd 日 一 二 三 四 五 六
ddd 周日 周一 ... 周五 周六
dddd 星期日 星期一 ... 星期五 星期六
年份 YYYY 1970 1971 ... 2029 2030
上午/下午 A 凌晨 早上 ... 下午 晚上
a 凌晨 早上 ... 下午 晚上
时刻 H 0 1 ... 22 23
HH 00 01 ... 22 23
h 1 2 ... 11 12
hh 01 02 ... 11 12
分钟 m 0 1 ... 58 59
mm 00 01 ... 58 59
s 0 1 ... 58 59
ss 00 01 ... 58 59
毫秒 S 0 1 ... 8 9
SS 00 01 ... 98 99
SSS 000 001 ... 998 999
Unix 时间戳 X 1495357559853
Unix 时间戳 毫秒 x 1495357559853

时差 (以现在为基准)

fromNow()

let fromNow = time('2017-01-01').fromNow()
console.log(fromNow) // 4个月前

倒计时

const time = require('time-formater')
let remain = 100000 // 10万秒
let countdown = time.countdown(remain)
let token = '剩余:d天H小时m分钟s秒'

// 浏览器
function step() {
    document.title = countdown.format(token) // 剩余:1天3小时46分钟40秒
    requestAnimationFrame(step)
}
step()

countdown(time)

  • time <number | string | Date> 类型为数字表示剩余的秒数,为Date实例或字符串(符合ISO 8601格式),表示结束的时间点。

返回倒计时的时间量。

format(token)

  • token <string> 用于指定输出格式。例:'剩余:d天H小时m分钟s秒' => "剩余:1天11小时4分钟38秒"。
token 描述
d 天数
H 小时数
m 分钟数
s 秒数
S 毫秒数
#<number> 前缀,表示在前面填充零到指定宽度。 例:#3d 表示将天数填充到3个字符,001 。

将时间量格式化为字符串。

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].