Created
May 1, 2020 04:29
-
-
Save dsolay/504b24772073104ec806b3fe53f66f03 to your computer and use it in GitHub Desktop.
JS Bin // source https://jsbin.com/cufunov
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
| <!DOCTYPE html> | |
| <html> | |
| <head> | |
| <meta charset="utf-8"> | |
| <meta name="viewport" content="width=device-width"> | |
| <title>JS Bin</title> | |
| </head> | |
| <body> | |
| <script id="jsbin-javascript"> | |
| // ISO8601 in local time zone | |
| const localISOString = (d) => { | |
| let pad = function (n){return n<10 ? '0'+n : n;} | |
| let tz = d.getTimezoneOffset(); | |
| let tzs = (tz>0?"-":"+") + pad(parseInt(Math.abs(tz/60))); | |
| if (tz%60 !== 0) | |
| tzs += pad(Math.abs(tz%60)); | |
| if (tz === 0) // Zulu time == UTC | |
| tzs = 'Z'; | |
| return `${d.getFullYear()}-${pad(d.getMonth()+1)}-${pad(d.getDate())}T${pad(d.getHours())}:${pad(d.getMinutes())}:${pad(d.getSeconds())}${tzs}`; | |
| }; | |
| console.log(localISOString(new Date(2020, 3, 30, 16, 53))); | |
| </script> | |
| <script id="jsbin-source-javascript" type="text/javascript">// ISO8601 in local time zone | |
| const localISOString = (d) => { | |
| let pad = function (n){return n<10 ? '0'+n : n;} | |
| let tz = d.getTimezoneOffset(); | |
| let tzs = (tz>0?"-":"+") + pad(parseInt(Math.abs(tz/60))); | |
| if (tz%60 !== 0) | |
| tzs += pad(Math.abs(tz%60)); | |
| if (tz === 0) // Zulu time == UTC | |
| tzs = 'Z'; | |
| return `${d.getFullYear()}-${pad(d.getMonth()+1)}-${pad(d.getDate())}T${pad(d.getHours())}:${pad(d.getMinutes())}:${pad(d.getSeconds())}${tzs}`; | |
| }; | |
| console.log(localISOString(new Date(2020, 3, 30, 16, 53)));</script></body> | |
| </html> |
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
| // ISO8601 in local time zone | |
| const localISOString = (d) => { | |
| let pad = function (n){return n<10 ? '0'+n : n;} | |
| let tz = d.getTimezoneOffset(); | |
| let tzs = (tz>0?"-":"+") + pad(parseInt(Math.abs(tz/60))); | |
| if (tz%60 !== 0) | |
| tzs += pad(Math.abs(tz%60)); | |
| if (tz === 0) // Zulu time == UTC | |
| tzs = 'Z'; | |
| return `${d.getFullYear()}-${pad(d.getMonth()+1)}-${pad(d.getDate())}T${pad(d.getHours())}:${pad(d.getMinutes())}:${pad(d.getSeconds())}${tzs}`; | |
| }; | |
| console.log(localISOString(new Date(2020, 3, 30, 16, 53))); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment