Skip to content

Instantly share code, notes, and snippets.

@mattmanning
Created August 17, 2019 14:59
Show Gist options
  • Save mattmanning/59c3ad345580256d1ffcbf45d893a9a0 to your computer and use it in GitHub Desktop.
Save mattmanning/59c3ad345580256d1ffcbf45d893a9a0 to your computer and use it in GitHub Desktop.
Localized timestamps

jQuery snippet to display a timestamp in local time zone and language

$(function() {
  $.each($('.timestamp'), function(i, v) {
	  ts = $(v)
		ts.text((new Date(ts.text())).toLocaleString());
	})
});

Return UTC timestamps from your server. Apply the timestamp class to any element containing them to format it on the frontend.

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