Featherlight (< 2kB) helper for Javascript date formatting

栏目: IT技术 · 发布时间: 6年前

内容简介:This project was bootstrapped with

Featherlight (< 2kB) helper for Javascript date formatting

Featherlight (
	

Sometimes all you need is just a simple date formatting without all of those super powers.

Name is taken from tempo and tempe

:package: Install

$ yarn add tempe

 or

$ npm install tempe --save

:computer: Usage

Use the default export, pass existing date object or you can initialize it like normal Javascript Date object.

import tempe from 'tempe';

// use tempe as Date initializer
tempe(2020, 0, 13).format('dd, DD MMM YYYY'); // "Monday, 13 Jan 2020"

// pass existing Date object to tempe
tempe(new Date(2020, 0, 13)).format('dd, DD MMM YYYY'); // "Monday, 13 Jan 2020"

// time formatting
tempe(2020, 2, 25, 23, 59).format('DD MMMM YYYY hh:mm:ss'); // "25 March 2020 23:59:00"
tempe(2020, 2, 25, 23, 59).format('H at DD/MM/YYYY'); // "11 PM at 25/03/2020"

:globe_with_meridians: i18n

Tempe supports internationalization by specifying the locale while formatting

import tempe from 'tempe';

tempe(2020, 5, 13).format('DD MMM YYYY', 'ja'); // "13日 6月 2020年"
tempe(2020, 5, 13).format('DD MMM YYYY', 'vi'); // "13 Tháng 6 2020"
tempe(2020, 5, 13).format('DD MMM YYYY', 'id'); // "13 Juni 2020"

:memo: List of all available formats

Format Output Description
YY 18 Two-digit year
YYYY 2018 Four-digit year
M 1-12 The month, beginning at 1
MM 01-12 The month, 2-digits
MMM Jan-Dec The abbreviated month name
MMMM January-December The full month name
D 1-31 The day of the month
DD 01-31 The day of the month
dd Sun-Sat The short name of the day of the week
ddd Sunday-Saturday The name of the day of the week
H 0-23 AM/PM The hour with AM/PM
h 01-12 The hour, 12-hour clock
hh 01-12 The hour, 12-hour clock
m 0-59 The minute
mm 00-59 The minute, 2-digits
s 0-59 The second
ss 00-59 The second, 2-digits

This project was bootstrapped with TSDX .


以上所述就是小编给大家介绍的《Featherlight (< 2kB) helper for Javascript date formatting》,希望对大家有所帮助,如果大家有任何疑问请给我留言,小编会及时回复大家的。在此也非常感谢大家对 码农网 的支持!

查看所有标签

猜你喜欢:

本站部分资源来源于网络,本站转载出于传递更多信息之目的,版权归原作者或者来源机构所有,如转载稿涉及版权问题,请联系我们

原则

原则

[美] 瑞·达利欧 / 刘波、綦相 / 中信出版社 / 2018-1 / CNY 98.00

※ 华尔街投资大神、对冲基金公司桥水创始人,人生经验之作 作者瑞·达利欧出身美国普通中产家庭,26岁时被炒鱿鱼后在自己的两居室内创办了桥水,现在桥水管理资金超过1 500亿美元,截至2015年年底,盈利超过450亿美元。达利欧曾成功预测2008年金融危机,现在将其白手起 家以来40多年的生活和工作原则公开。 ※ 多角度、立体阐述生活、工作、管理原则 包含21条高原则、139条中原......一起来看看 《原则》 这本书的介绍吧!

图片转BASE64编码
图片转BASE64编码

在线图片转Base64编码工具

HTML 编码/解码
HTML 编码/解码

HTML 编码/解码

UNIX 时间戳转换
UNIX 时间戳转换

UNIX 时间戳转换