dayjs README

The project's README from github.com/iamkun/dayjs. As one markdown file: README.md.

English | 简体中文 | 日本語 | Português Brasileiro | 한국어 | Español (España) | Русский | Türkçe | සිංහල | עברית

Day.js

Fast 2kB alternative to Moment.js with the same modern API

Gzip Size NPM Version Build Status Codecov License
Sauce Test Status

Day.js is a minimalist JavaScript library that parses, validates, manipulates, and displays dates and times for modern browsers with a largely Moment.js-compatible API. If you use Moment.js, you already know how to use Day.js.

dayjs().startOf('month').add(1, 'day').set('year', 2018).format('YYYY-MM-DD HH:mm:ss');

Getting Started

Documentation

You can find more details, API, and other docs on day.js.org website.

Installation

npm install dayjs --save

📚Installation Guide

API

It's easy to use Day.js APIs to parse, validate, manipulate, and display dates and times.

dayjs('2018-08-08') // parse

dayjs().format('{YYYY} MM-DDTHH:mm:ss SSS [Z] A') // display

dayjs().set('month', 3).month() // get & set

dayjs().add(1, 'year') // manipulate

dayjs().isBefore(dayjs()) // query

📚API Reference

I18n

Day.js has great support for internationalization.

But none of them will be included in your build unless you use them.

import 'dayjs/locale/es' // load on demand

dayjs.locale('es') // use Spanish locale globally

dayjs('2018-05-05').locale('zh-cn').format() // use Chinese Simplified locale in a specific instance

📚Internationalization

Plugin

A plugin is an independent module that can be added to Day.js to extend functionality or add new features.

import advancedFormat from 'dayjs/plugin/advancedFormat' // load on demand

dayjs.extend(advancedFormat) // use plugin

dayjs().format('Q Do k kk X x') // more available formats

📚Plugin List

Downloads

Day.js Chart

Sponsors

Support this project by becoming a sponsor. Your logo will show up here with a link to your website.

[Become a sponsor via Github] [Become a sponsor via OpenCollective]

                                    Sayfone Cheap international calls                   BestKru                   Route Optimizer and Route Planner Software                                    

Contributors

This project exists thanks to all the people who contribute.

Please give us a 💖 star 💖 to support us. Thank you.

And thank you to all our backers! 🙏

License

Day.js is licensed under a MIT License.

dayjs (iamkun/dayjs)

Searching Database…

48.7K ·GitHub
这是什么?Day.js 是一个极简的 JavaScript 库,用于解析、校验、操作和显示日期与时间,是 Moment.js 的轻量级替代品。
它是 Moment.js 的直接替代品,还是别的东西?它是一个 API 基本兼容 Moment.js 的库,所以如果你已经会用 Moment.js,也就会用 Day.js,不过两者并不是同一套代码。
我该如何把它添加到项目中?通过包管理器(例如 npm)安装,再把 Day.js 导入到代码中;文档网站上链接了一份专门的安装指南。
要使用语言包或扩展功能,我还需要额外设置吗?语言包和扩展功能都是可选的插件或模块,默认不内置,因此只需加载所需部分,以保持体积小巧。
开箱即用时,我得不到哪些功能?核心包有意不包含国际化语言包和额外功能;如要在精简核心之外扩展 Day.js,必须显式添加插件。
它能在所有浏览器中运行,还是只支持现代浏览器?Day.js 是为现代浏览器设计的,不过 README 中写明支持所有浏览器。
Day.js 与 Moment.js 相比有多大?Day.js 经过压缩和 gzip 后仅约 2kB,远小于 Moment.js,同时保持相近的 API。
Day.js 像某些日期库那样可以修改吗?不可以,Day.js 对象是不可变的;每次操作都会返回一个新实例,而不会修改原对象。
我可以链式调用日期操作吗?可以,Day.js 的方法支持链式调用,因此可以在一个表达式中组合多个操作。
Day.js 开箱即支持哪些语言?README 本身已被翻译成英语、中文、日语、葡萄牙语、韩语、西班牙语、俄语、土耳其语、僧伽罗语和希伯来语,同时 Day.js 还提供了用于日期本地化格式化的国际化插件。
Creator
iamkun
Size
6 MB
Stars
48.7K
Age
8y
Commits · 90 Days