-
-
Save patricmutwiri/07d40257f23292496159 to your computer and use it in GitHub Desktop.
This file contains 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
// X-browser yyyy-MM-dd HH:mm:ss TZInfo | |
// @author noromanba http://flavors.me/noromanba | |
// @license CC0 Univ PD http://creativecommons.org/publicdomain/zero/1.0 | |
// c.f. | |
// https://gist.github.com/noromanba/6736822 | |
// http://let.hatelabo.jp/noromanba/let/hJmcrJfO94ka/rev/hJmcruLM2p0H | |
// http://let.hatelabo.jp/noromanba/let/hJmcrJfO94ka | |
var toDateTimeTZInfoString = (function () { | |
// non-standard JS 1.6, Fx only; c.f. | |
// http://compatibility.shwups-cms.ch/en/home/?&&&property=Date.prototype.toLocaleFormat | |
// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/toLocaleFormat | |
if (Date.prototype.toLocaleFormat) { | |
return function () { | |
return new Date().toLocaleFormat('%Y-%m-%d %T %Z'); | |
}; | |
} | |
// Fx not supported yet; c.f. | |
// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/toLocaleString | |
// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/toLocaleDateString | |
if (Date.prototype.toLocaleDateString) { | |
return function () { | |
var now = new Date(); | |
return now.toLocaleDateString('ja', { | |
year: 'numeric', | |
month: '2-digit', | |
day: '2-digit' | |
}).replace(/\//g, '-') + ' ' + now.toTimeString(); | |
}; | |
} | |
// Safari, almost browsers and mobile | |
return function () { | |
var now = new Date(); | |
return [ | |
now.getFullYear(), | |
'-', ('0' + (now.getMonth() + 1)).slice(-2), | |
'-', ('0' + now.getDate()).slice(-2), | |
' ', now.toTimeString() | |
].join(''); | |
}; | |
})(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment