Skip to content

Instantly share code, notes, and snippets.

@singhmohancs
Forked from fntneves/utc.js
Created July 22, 2017 21:03
Show Gist options
  • Save singhmohancs/fd2a5f91387f1f1f73edce54e40403d1 to your computer and use it in GitHub Desktop.
Save singhmohancs/fd2a5f91387f1f1f73edce54e40403d1 to your computer and use it in GitHub Desktop.
Moment.JS - Convert UTC to Local Time
$.fn.format = function() {
return this.each(function() {
var $this = $(this);
var time = $this.attr("datetime");
var localTime = moment.utc(time).local().format();
$this.attr("datetime", localTime).timeago();
return this;
});
};
@singhmohancs
Copy link
Author

Example:

$('#started_at').html(moment.utc("2017-07-22 20:53:14").local().format('MM/DD/YYYY h:mm:ss a'));

$('#ends_at').html(moment.utc("2017-07-22 21:23:14").local().format('MM/DD/YYYY h:mm:ss a'));

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment