Convert Unix timestamp to DD / MM / YYYY HH : MM : SS format | Function to convert unix time to Human readable format ; Save the time in Human readable format ; Number of days in month in normal year ; Calculate total days unix time T ; Calculating current year ; Updating extradays because it will give days till previous day and we have include current day ; Calculating MONTH and DATE ; Current Month ; Calculating HH : MM : YYYY ; Return the time ; Given unix time ; Function call to convert unix time to human read able ; Print time in format DD : MM : YYYY : HH : MM : SS
function unixTimeToHumanReadable ( seconds ) { let ans = " " ; let daysOfMonth = [ 31 , 28 , 31 , 30 , 31 , 30 , 31 , 31 , 30 , 31 , 30 , 31 ] ; let currYear , daysTillNow , extraTime , extraDays , index , date , month , hours , minutes , secondss , flag = 0 ; daysTillNow = parseInt ( seconds / ( 24 * 60 * 60 ) , 10 ) ; extraTime = seconds % ( 24 * 60 * 60 ) ; currYear = 1970 ; while ( daysTillNow >= 365 ) { if ( currYear % 400 == 0 || ( currYear % 4 == 0 && currYear % 100 != 0 ) ) { daysTillNow -= 366 ; } else { daysTillNow -= 365 ; } currYear += 1 ; } extraDays = daysTillNow + 1 ; if ( currYear % 400 == 0 || ( currYear % 4 == 0 && currYear % 100 != 0 ) ) flag = 1 ; month = 0 ; index = 0 ; if ( flag == 1 ) { while ( true ) { if ( index == 1 ) { if ( extraDays - 29 < 0 ) break ; month += 1 ; extraDays -= 29 ; } else { if ( extraDays - daysOfMonth [ index ] < 0 ) { break ; } month += 1 ; extraDays -= daysOfMonth [ index ] ; } index += 1 ; } } else { while ( true ) { if ( extraDays - daysOfMonth [ index ] < 0 ) { break ; } month += 1 ; extraDays -= daysOfMonth [ index ] ; index += 1 ; } } if ( extraDays > 0 ) { month += 1 ; date = extraDays ; } else { if ( month == 2 && flag == 1 ) date = 29 ; else { date = daysOfMonth [ month - 1 ] ; } } hours = parseInt ( extraTime / 3600 , 10 ) ; minutes = parseInt ( ( extraTime % 3600 ) / 60 , 10 ) ; secondss = parseInt ( ( extraTime % 3600 ) % 60 , 10 ) ; ans += date . toString ( ) ; ans += " " ; ans += month . toString ( ) ; ans += " " ; ans += currYear . toString ( ) ; ans += " " ; ans += hours . toString ( ) ; ans += " " ; ans += minutes . toString ( ) ; ans += " " ; ans += secondss . toString ( ) ; return ans ; } let T = 1595497956 ; let ans = unixTimeToHumanReadable ( T ) ; document . write ( ans + " " ) ;