File tree 2 files changed +34
-26
lines changed
2 files changed +34
-26
lines changed Original file line number Diff line number Diff line change 1
1
a tool for transferring timestamp to standard time format
2
2
3
- # usage
3
+ # Date
4
+
5
+
6
+ | Name | Description | Example |
7
+ | --- | --- | --- |
8
+ | YYYY | Year | 2017 |
9
+ | MM | Month | 02 |
10
+ | DD | Date | 01 |
11
+ | hh | Hour | 23 |
12
+ | mm | Minute | 01 |
13
+ | ss | Second | 02 |
14
+
15
+ Above is time-schema-formatter supported format. You can make your own time format. For example:
16
+
17
+ - YYYY/MM/DD hh:mm: ss | 2017/06/07 23:01:02
18
+ - YYYY年MM月DD日 hh-mm-ss | 2017年06月07日 23-01-02
19
+ - YYYY-MM-DD | 2017-06-07
20
+
21
+ # Usage
4
22
5
23
``` javascript
6
24
import timeFormat from ' time-schema-formatter'
7
25
8
- const now = Date .parse (new Date ())
9
-
10
- // 2017-06-09
26
+ // 2017/06/09 23:01:02
11
27
timeFormat ({
12
- time: Date .parse (new Date ()),
13
- format: ' detail ' ,
28
+ time: Date .parse (new Date ()),
29
+ format: ' YYYY/MM/DD hh:mm:ss ' ,
14
30
});
15
31
16
- // 20170609
32
+ // 2017年06月09日 23-01-02
17
33
timeFormat ({
18
- time: Date .parse (new Date ()),
19
- format: ' row ' ,
34
+ time: Date .parse (new Date ()),
35
+ format: ' YYYY年MM月DD日 hh-mm-ss ' ,
20
36
});
21
37
22
38
// 2017-06-09
23
39
timeFormat ({
24
- time: Date .parse (new Date ()),
25
- format: ' slash ' ,
40
+ time: Date .parse (new Date ()),
41
+ format: ' YYYY-MM-DD ' ,
26
42
});
27
43
```
Original file line number Diff line number Diff line change @@ -8,21 +8,13 @@ function getTime(option) {
8
8
const min = date . getMinutes ( ) < 10 ? `0${ date . getMinutes ( ) } ` : date . getMinutes ( ) ;
9
9
const sec = date . getSeconds ( ) < 10 ? `0${ date . getSeconds ( ) } ` : date . getSeconds ( ) ;
10
10
11
- let times ;
12
- switch ( option . format ) {
13
- case 'detail' :
14
- times = `${ year } .${ month } .${ day } ${ hour } :${ min } :${ sec } ` ;
15
- break ;
16
- case 'row' :
17
- times = `${ year } ${ month } ${ day } ` ;
18
- break ;
19
- case 'slash' :
20
- times = `${ year } -${ month } -${ day } ` ;
21
- break ;
22
- default :
23
- times = option . time ;
24
- break ;
25
- }
11
+ let times = option . format ;
12
+ times = times . replace ( 'YYYY' , year ) ;
13
+ times = times . replace ( 'MM' , month ) ;
14
+ times = times . replace ( 'DD' , day ) ;
15
+ times = times . replace ( 'hh' , hour ) ;
16
+ times = times . replace ( 'mm' , min ) ;
17
+ times = times . replace ( 'ss' , sec ) ;
26
18
27
19
return times
28
20
You can’t perform that action at this time.
0 commit comments