Skip to content

Instantly share code, notes, and snippets.

@fixable11
Created August 12, 2018 15:34
Show Gist options
  • Save fixable11/b5095b478e0e759190ebc7f39356a030 to your computer and use it in GitHub Desktop.
Save fixable11/b5095b478e0e759190ebc7f39356a030 to your computer and use it in GitHub Desktop.
Translates UTC timestamp to local date
//Translates UTC timestamp to local date
function newDate($selector){
var $UTCtimestamp = $($selector).data('timestamp');
var $localData = new Date($UTCtimestamp * 1000);
var $date = "0" + $localData.getDate();
var $mount = "0" + ($localData.getMonth() + 1);
var $year = $localData.getFullYear();
var $hours = $localData.getHours();
var $minutes = "0" + $localData.getMinutes();
var $seconds = "0" + $localData.getSeconds();
var $formattedDate = $date.substr(-2) + '.' + $mount.substr(-2) + '.' + $year;
var $formattedTime = $hours + ':' + $minutes.substr(-2) + ':' + $seconds.substr(-2);
$($selector).html($formattedDate + ' ' + $formattedTime);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment