Created
November 27, 2019 07:23
-
-
Save kou10mo/8adf5e96a6d8f25a4d9e4328da632643 to your computer and use it in GitHub Desktop.
Mysql等の日時からISO-8601形式に変換
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| /** | |
| * https://qiita.com/unbabel/items/12487e85525ba1ec1618の改良版 | |
| */ | |
| function replaceDate(dateStr) { | |
| const regexp = /^([0-9]{2,4})-([0-1][0-9])-([0-3][0-9])(?: ([0-2][0-9]):([0-5][0-9]):([0-5][0-9]))?$/; | |
| return dateStr.replace(regexp, (match, year, month, day, hour, minutes, seconds) => { | |
| console.log(hour); | |
| if (!hour) { | |
| return `${year}-${month}-${ day}T00:00:00.000+09:00`; | |
| } else { | |
| return `${year}-${month}-${ day}T${hour}:${minutes}:${seconds}.000+09:00`; | |
| } | |
| }); | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment