[Python] Using epoch time in seconds to display days since epoch, years since epoch and hours,...

Discussão em 'Python' iniciado por Stack, Fevereiro 24, 2025.

  1. Stack

    Stack Membro Participativo

    import time


    #Program is supposed to use epoch time to accurately display to
    #user the amount of days since epoch, years since epoch and
    #display the time hours, minutes and seconds.


    epoch = time.time()#get amount fo seconds that passed since epoch
    hour_seconds = 3600
    day_in_seconds = hour_seconds * 24
    days_since_epoch = int(epoch//day_in_seconds)
    print(days_since_epoch,"days")
    years_since_epoch = int(epoch//(day_in_seconds * 365))
    print(years_since_epoch,"years")
    remainder = int(epoch % day_in_seconds)
    print(remainder)
    hours = remainder // hour_seconds
    print(hours)
    new_remainder = remainder % hour_seconds
    minutes = new_remainder // 60
    print(minutes)
    seconds = new_remainder % 60
    print(seconds)


    The program works when I calculate minutes and seconds. The program does not work when it comes to displaying hours.

    Continue reading...

Compartilhe esta Página