Skip to content

Instantly share code, notes, and snippets.

@edalis
Created May 10, 2018 08:46
Show Gist options
  • Save edalis/42d9685d470446eb5afce34c6fa8c14f to your computer and use it in GitHub Desktop.
Save edalis/42d9685d470446eb5afce34c6fa8c14f to your computer and use it in GitHub Desktop.
JavaScript Time Converter
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