File tree 3 files changed +37
-0
lines changed
solution/1500-1599/1507.Reformat Date
3 files changed +37
-0
lines changed Original file line number Diff line number Diff line change @@ -143,6 +143,20 @@ class Solution {
143
143
}
144
144
```
145
145
146
+ ### ** TypeScript**
147
+
148
+ ``` ts
149
+ function reformatDate(date : string ): string {
150
+ const s = date .split (' ' );
151
+ const months = ' JanFebMarAprMayJunJulAugSepOctNovDec' ;
152
+ const day = parseInt (s [0 ].substring (0 , s [0 ].length - 2 ));
153
+ const month = Math .floor (months .indexOf (s [1 ]) / 3 ) + 1 ;
154
+ return ` ${s [2 ]}-${month .toString ().padStart (2 , ' 0' )}-${day
155
+ .toString ()
156
+ .padStart (2 , ' 0' )} ` ;
157
+ }
158
+ ```
159
+
146
160
### ** ...**
147
161
148
162
```
Original file line number Diff line number Diff line change @@ -130,6 +130,20 @@ class Solution {
130
130
}
131
131
```
132
132
133
+ ### ** TypeScript**
134
+
135
+ ``` ts
136
+ function reformatDate(date : string ): string {
137
+ const s = date .split (' ' );
138
+ const months = ' JanFebMarAprMayJunJulAugSepOctNovDec' ;
139
+ const day = parseInt (s [0 ].substring (0 , s [0 ].length - 2 ));
140
+ const month = Math .floor (months .indexOf (s [1 ]) / 3 ) + 1 ;
141
+ return ` ${s [2 ]}-${month .toString ().padStart (2 , ' 0' )}-${day
142
+ .toString ()
143
+ .padStart (2 , ' 0' )} ` ;
144
+ }
145
+ ```
146
+
133
147
### ** ...**
134
148
135
149
```
Original file line number Diff line number Diff line change
1
+ function reformatDate ( date : string ) : string {
2
+ const s = date . split ( ' ' ) ;
3
+ const months = ' JanFebMarAprMayJunJulAugSepOctNovDec' ;
4
+ const day = parseInt ( s [ 0 ] . substring ( 0 , s [ 0 ] . length - 2 ) ) ;
5
+ const month = Math . floor ( months . indexOf ( s [ 1 ] ) / 3 ) + 1 ;
6
+ return `${ s [ 2 ] } -${ month . toString ( ) . padStart ( 2 , '0' ) } -${ day
7
+ . toString ( )
8
+ . padStart ( 2 , '0' ) } `;
9
+ }
You can’t perform that action at this time.
0 commit comments