Uh oh!
There was an error while loading.Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork0
uiwjs/date-formatter
Folders and files
| Name | Name | Last commit message | Last commit date | |
|---|---|---|---|---|
Repository files navigation
Get a formatted date.
$ npm install --save @uiw/formatter
importformatterfrom'@uiw/formatter';console.log(formatter());//=> 2019-03-07console.log(formatter.utc());//=> 2019-03-07console.log(formatter('YYYY年MM月DD日',newDate(2019,3,7)))//=> 2019年04月07日console.log(formatter('YYYY年MM月DD日 16:30:29',newDate(2019,3,7,16,30,29)))//=> 2019年04月07日 16:30:29console.log(formatter('YYYY年MM月DD日 HH:mm-ss',newDate(2019,3,7,16,30,29)))//=> 2019年04月07日 16:30-29console.log(formatter('YYYY/MM/DD HH:mm:ss',newDate(2019,3,7,16,30,29)))//=> 2019年04月07日 16:30-29console.log(formatter('YYYY/MM/DD HH:mm:ss',newDate(2019,3,7,16,30,29)))//=> 2019/04/07 16:30:29console.log(formatter('YYYY'));//=> 2019console.log(formatter.utc('YYYY'));//=> 2019
Or manually download and linkformatter.js in your HTML, It can also be downloaded viaUNPKG:
<divid="date"></div><scriptsrc="https://unpkg.com/@uiw/formatter/dist/formatter.min.js"></script><script>document.getElementById('date').innerHTML=formatter();</script>
The aboveexample preview.
Resolve changes in time zone, resulting in inaccurate display server time
functiontimeZoneConverter(date,timeZone){constoldDate=newDate(date);constnewDate=newDate();conststamp=oldDate.getTime();if(!timeZone)returnoldDate;return(isNaN(timeZone)&&!timeZone) ?oldDate :newDate(stamp+(newDate.getTimezoneOffset()*60*1000)+(timeZone*60*60*1000));}timeZoneConverter(newDate(1434701732*1000),8)
formatter(rule:String,date:Date,utc:Boolean);formatter.utc(rule:String,date:Date);
| rule | Description | 中文说明 | E.g |
|---|---|---|---|
YYYY | full year | 年 | 2019 |
MM | month | 月 | 02 |
DD | day | 天 | 05 |
HH | hours | 时 | 12 |
mm | minutes | 分钟 | 59 |
ss | seconds | 秒 | 09 |
ms | milliseconds | 毫秒 | 532 |
About
Get a formatted date.
Topics
Resources
License
Uh oh!
There was an error while loading.Please reload this page.
Stars
Watchers
Forks
Sponsor this project
Uh oh!
There was an error while loading.Please reload this page.
Packages0
No packages published
Uh oh!
There was an error while loading.Please reload this page.
Contributors5
Uh oh!
There was an error while loading.Please reload this page.