Skip to content

Instantly share code, notes, and snippets.

@kylekatarnls
Created January 29, 2019 14:08
Show Gist options
  • Select an option

  • Save kylekatarnls/2e096d295fb0a4140d7985d23d6e70cb to your computer and use it in GitHub Desktop.

Select an option

Save kylekatarnls/2e096d295fb0a4140d7985d23d6e70cb to your computer and use it in GitHub Desktop.
var lang = 'fr';
var timezone = 'Europe/Paris'; // Use timezone = null to use the browser timezone
moment.prototype.userFormat = function (format) {
if (timezone) {
this.tz(timezone);
}
if (lang) {
this.locale(lang);
}
if (format) {
return this.format(format);
}
return this.calendar();
};
console.log(
moment('2018-05-12T23:16:46.123456Z').userFormat()
);
console.log(
moment('2018-05-12T23:16:46.123456Z').userFormat('LLLL')
);
console.log(
moment('2018-05-12T23:16:46.123456Z').userFormat('dd Do YY')
);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment