Skip to content

Instantly share code, notes, and snippets.

@ZaneHannanAU
Created November 10, 2016 06:36
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ZaneHannanAU/19b83925836b420aa86e35fe7f8b2f9b to your computer and use it in GitHub Desktop.
Save ZaneHannanAU/19b83925836b420aa86e35fe7f8b2f9b to your computer and use it in GitHub Desktop.
// Server side NodeJS.
var dateFormat = module.exports = {}
dateFormat.opts = {
day: 'numeric',
hour: 'numeric',
minute: 'numeric',
month: 'long',
weekday: 'long',
year: 'numeric',
timeZoneName: 'long'
}
dateFormat.format = function(date, locale) {
return new Date(date).toLocaleDateString(
({}||locale),
dateFormat.opts
)
}
dateFormat.atNow = function(locale) {
return dateFormat.format(
Date.now(),
locale
)
}
dateFormat.numeric = function(date) {
return new Date(date).valueOf;
}
dateFormat.UTC = function(date) {
return new Date(date||Date.now()).toISOString();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment