Format displayed time.
// add zero to hour, minute or second when < 1000
var addZero = function(i) {
if (i < 10) {
i = "0" + i;
}
return i;
};
// return formatted time
var formatTime = function(time) {
var timeformat = '';
var nowYear = new Date().getFullYear();
var nowMonth = new Date().getMonth();
var nowDay = new Date().getDay();
var thenYear = new Date(parseInt(time, 10)).getFullYear();
var thenMonth = new Date(parseInt(time, 10)).getMonth();
// month names in whatever language you want
var monthName = ['január', 'február', 'március', 'április', 'május', 'június', 'július', 'augusztus', 'szeptember', 'október', 'november', 'december'];
var thenDay = new Date(parseInt(time, 10)).getDate();
var thenHour = new Date(parseInt(time, 10)).getHours();
var thenMin = new Date(parseInt(time, 10)).getMinutes();
var thenSec = new Date(parseInt(time, 10)).getSeconds();
if (nowYear !== thenYear){
timeformat = thenYear+'. '+monthName[thenMonth]+' '+thenDay+'.';
} else if(nowMonth !== thenMonth || nowDay !== thenDay) {
timeformat = monthName[thenMonth]+' '+thenDay+'.';
}
return timeformat+' '+addZero(thenHour)+':'+addZero(thenMin)+':'+addZero(thenSec);
};