Created
February 24, 2021 20:14
-
-
Save Rplus/ddc44e4634e662e7902b5b78a96033c0 to your computer and use it in GitHub Desktop.
format local date with JSON format
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://stackoverflow.com/a/11172083 | |
function toJSONLocal (date = new Date()) { | |
var local = new Date(date); | |
local.setMinutes(date.getMinutes() - date.getTimezoneOffset()); | |
return local.toJSON().slice(0, 10); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
toLocaleDateString
with option support: IE11+https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/toLocaleDateString