Skip to content

Instantly share code, notes, and snippets.

@nikitaeverywhere
Last active August 29, 2015 14:14
Show Gist options
  • Save nikitaeverywhere/7f945504a0e567adfd24 to your computer and use it in GitHub Desktop.
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)
/**
* 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