Created
May 10, 2018 08:46
-
-
Save edalis/42d9685d470446eb5afce34c6fa8c14f to your computer and use it in GitHub Desktop.
JavaScript Time Converter
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
function timeConverter(UNIX_timestamp) { | |
const months = ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec']; | |
const monthsRu = ['Января', 'Февраля', 'Марта', 'Апреля', 'Мая', 'Июня', 'Июля', 'Августа', 'Сентября', 'Октября', 'Ноября', 'Декабря']; | |
let date = new Date(UNIX_timestamp); | |
let year = date.getFullYear(); | |
let month = monthsRu[date.getMonth()]; | |
let day = date.getDate(); | |
let hour; | |
date.getHours() >= 10 ? hour = date.getHours() : hour = '0' + date.getHours(); | |
let min; | |
date.getMinutes() >= 10 ? min = date.getMinutes() : min = '0' + date.getMinutes(); | |
let sec; | |
date.getSeconds() >= 10 ? sec = date.getSeconds() : sec = '0' + date.getSeconds(); | |
return time = `${day} ${month} ${year}, ${hour}:${min}:${sec}`; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment