Last active
August 29, 2015 14:14
-
-
Save nikitaeverywhere/7f945504a0e567adfd24 to your computer and use it in GitHub Desktop.
NodeJS date formatting function (appeared because NodeJS is not using the system locale and Date.toLocaleString gives unexpected result)
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
/** | |
* Converts any date to "DD.MM.YYYY, hh:mm:ss" string. | |
* Workaround for NodeJS Date.toLocaleString implementation. | |
* | |
* @param {Date} date - Date to format. | |
* @returns {string} - Formatted date string. | |
*/ | |
var formatDate = function (date) { | |
return date.toISOString().replace(/(\d+)\-(\d+)\-(\d+)T\s?([^\.]*)\..*/, "$3.$2.$1, $4"); | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment