Last active
February 23, 2018 04:48
-
-
Save koki-h/6b084e937ef990156f8f50a939b4169e to your computer and use it in GitHub Desktop.
swiftのtimeIntervalSinceReferenceDateで生成した日付数値をjsでパースする
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
| // SwiftのtimeIntervalSinceReferenceDateは'2001-01-01 00:00:00 UTC'からの経過秒数を返すため | |
| // jsでは'2001-01-01 00:00:00 UTC'のUnixタイムを加算して日付に変換する。 | |
| // またjsでは時刻をミリ秒単位で扱うので注意を要する。 | |
| // see: https://developer.apple.com/documentation/foundation/nsdate/1417376-timeintervalsincereferencedate | |
| process.stdin.resume(); | |
| process.stdin.setEncoding('utf8'); | |
| // Your code here! | |
| var reference_time = Date.parse('2001-01-01 00:00:00 UTC'); | |
| var swift_time = 541047955; //example | |
| var d = new Date(swift_time * 1000 + reference_time); | |
| console.log(d); //2018-02-23T03:05:55.000Z |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment