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 ; Driver code ; Given unix time ; Function call to convert unix time to human read able ; Print time in format DD : MM : YYYY : HH : MM : SS
def unixTimeToHumanReadable ( seconds ) : NEW_LINE INDENT ans = " " NEW_LINE daysOfMonth = [ 31 , 28 , 31 , 30 , 31 , 30 , 31 , 31 , 30 , 31 , 30 , 31 ] NEW_LINE ( currYear , daysTillNow , extraTime , extraDays , index , date , month , hours , minutes , secondss , flag ) = ( 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 ) NEW_LINE daysTillNow = seconds // ( 24 * 60 * 60 ) NEW_LINE extraTime = seconds % ( 24 * 60 * 60 ) NEW_LINE currYear = 1970 NEW_LINE while ( daysTillNow >= 365 ) : NEW_LINE INDENT if ( currYear % 400 == 0 or ( currYear % 4 == 0 and currYear % 100 != 0 ) ) : NEW_LINE INDENT daysTillNow -= 366 NEW_LINE DEDENT else : NEW_LINE INDENT daysTillNow -= 365 NEW_LINE DEDENT currYear += 1 NEW_LINE DEDENT extraDays = daysTillNow + 1 NEW_LINE if ( currYear % 400 == 0 or ( currYear % 4 == 0 and currYear % 100 != 0 ) ) : NEW_LINE INDENT flag = 1 NEW_LINE DEDENT month = 0 NEW_LINE index = 0 NEW_LINE if ( flag == 1 ) : NEW_LINE INDENT while ( True ) : NEW_LINE INDENT if ( index == 1 ) : NEW_LINE INDENT if ( extraDays - 29 < 0 ) : NEW_LINE INDENT break NEW_LINE DEDENT month += 1 NEW_LINE extraDays -= 29 NEW_LINE DEDENT else : NEW_LINE INDENT if ( extraDays - daysOfMonth [ index ] < 0 ) : NEW_LINE INDENT break NEW_LINE DEDENT month += 1 NEW_LINE extraDays -= daysOfMonth [ index ] NEW_LINE DEDENT index += 1 NEW_LINE DEDENT DEDENT else : NEW_LINE INDENT while ( True ) : NEW_LINE INDENT if ( extraDays - daysOfMonth [ index ] < 0 ) : NEW_LINE INDENT break NEW_LINE DEDENT month += 1 NEW_LINE extraDays -= daysOfMonth [ index ] NEW_LINE index += 1 NEW_LINE DEDENT DEDENT if ( extraDays > 0 ) : NEW_LINE INDENT month += 1 NEW_LINE date = extraDays NEW_LINE DEDENT else : NEW_LINE INDENT if ( month == 2 and flag == 1 ) : NEW_LINE INDENT date = 29 NEW_LINE DEDENT else : NEW_LINE INDENT date = daysOfMonth [ month - 1 ] NEW_LINE DEDENT DEDENT hours = extraTime // 3600 NEW_LINE minutes = ( extraTime % 3600 ) // 60 NEW_LINE secondss = ( extraTime % 3600 ) % 60 NEW_LINE ans += str ( date ) NEW_LINE ans += " / " NEW_LINE ans += str ( month ) NEW_LINE ans += " / " NEW_LINE ans += str ( currYear ) NEW_LINE ans += " ▁ " NEW_LINE ans += str ( hours ) NEW_LINE ans += " : " NEW_LINE ans += str ( minutes ) NEW_LINE ans += " : " NEW_LINE ans += str ( secondss ) NEW_LINE return ans NEW_LINE DEDENT if __name__ == " _ _ main _ _ " : NEW_LINE INDENT T = 1595497956 NEW_LINE ans = unixTimeToHumanReadable ( T ) NEW_LINE print ( ans ) NEW_LINE DEDENT