OKyJIucT
8/6/2014 - 3:14 PM

Произвольная дата в JS

Произвольная дата в JS

function formatDate(unix_timestamp) {

    var currentDate = new Date(unix_timestamp * 1000);

    var year = currentDate.getFullYear();
    var month = parseInt(currentDate.getMonth()) + 1;
    month = "0" + month;
    var day = "0" + currentDate.getDate();

    var hours = currentDate.getHours();
    var minutes = "0" + currentDate.getMinutes();
    var seconds = "0" + currentDate.getSeconds();

    var formattedTime = year + '-' + month.substr(-2) + '-' + day.substr(-2) + ' ' + hours + ':' + minutes.substr(-2) + ':' + seconds.substr(-2);

    return formattedTime;

}


year.toString().substr(-2);