Now
Now is a time toolkit for javascript
Overview
Now is inspire by Now(a time toolkit for golang). When I'm about to complete the code, I found that this is just a total toy. go's standard library time native support Format, Duration and so on. Format and i18n needs a huge amount of work. I found that moment had implemented them in a very elegant way. So I borrow it, respect and gratitude!
Install
Install with npm
npm install now.js
ES6/commonjs
// ES6; // commonjsvar Now = ;
Import now.js into your page
// default support 'en' and 'zh-cn' // or locale version support 118 languages
Examples
var now = now // "2017-11-20T22:23:00+08:00"now // "2017-11-20 22:23:00.285"now // "Monday, November 20th 2017, 10:23:00 pm" now // default support 'en' and 'zh-cn'now // "星期一, 十一月 20日 2017, 10:23:00 晚上"now // "10 天前"// same asnow // "10 天前" // mondaynow // "2017-11-20 00:00:00" // isMondaynow // true // isBeforenow // true // isLeapYearnow // falsenow // true // betweennow // true // UTCnow // "2017-11-20T22:23:00+00:00" now // "2017-11-20 22:23:00"now // "2017-11-20 22:00:00"now // "2017-11-20 00:00:00"now // "2017-11-19 00:00:00"nowfirstDayMonday = true // Set Monday as first day, default is Sundaynow // "2017-11-20 00:00:00"now // "2017-11-01 00:00:00"now // "2017-10-01 00:00:00"now // "2017-01-01 00:00:00" now // "2017-11-20 22:23:59.999"now // "2017-11-20 22:59:59.999"now // "2017-11-20 23:59:59.999"now // "2017-11-25 23:59:59.999"nowfirstDayMonday = true // Set Monday as first day, default is Sundaynow // "2017-11-26 23:59:59.999"now // "2017-11-30 23:59:59.999"now // "2017-12-31 23:59:59.999"now // "2017-12-31 23:59:59.999" All the above functions return String type You can pass 'self' to return Now instance: var beginningOfMinute = now // return Now instancebeginningOfMinute // "Mon, PM10"beginningOfMinute // "Monday, November 20, 2017 10:23 PM"beginningOfMinute // true
Localization
From now.js
0.3.0, default just supports 'en' and 'zh-cn'.If you want to support more locales. Please use nowjs.locale.js
or nowjs.locale.min.js
instead.
Browser Support
Modern browsers and Internet Explorer 9+.
Contribute
Bug reports or suggestions please check out issues.
Any pull request will be apreciated.
- Fork
- run
npm install
- run
npm run start
in the main folder to launch a development webserver - complete your code and create pull request
Note:
- Pull request to
master
branch will be rejected, submit your pull request todevelop
branch. - Do not upload build files in your pull request. These are
dist/*.js
. I will build them by myself.
Changelog
0.3.0
- default version(nowjs.js, nowjs.min.js) and locale version(nowjs.locale.js, nowjs.locale.min.js).
- default version just supports 'en' and 'zh-cn' locales; locale version support 118 languages.
0.2.0
- fix package.json homepage, repository url and bugs url.
- add Contribute to readme.
Author
hongmaoxiao
License
MIT