Created
August 12, 2018 15:34
-
-
Save fixable11/b5095b478e0e759190ebc7f39356a030 to your computer and use it in GitHub Desktop.
Translates UTC timestamp to local date
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//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