Answers for "from seconds to date python"

1

seconds to days python

def show_time(time):
        time = int(time)
        day = time // (24 * 3600)
        time = time % (24 * 3600)
        hour = time // 3600
        time %= 3600
        minutes = time // 60
        time %= 60
        seconds = time
        if day != 0:
                return "%dD %dH %dM %dS" % (day, hour, minutes, seconds)
        elif day == 0 and hour != 0:
                return "%dH %dM %dS" % (hour, minutes, seconds)
        elif day == 0 and hour == 0 and minutes != 0:
                return "%dM %dS" % (minutes, seconds)
        else:
                return "%dS" % (seconds)

print(show_time(12345))
Posted by: Guest on September-11-2020
1

python datetime to seconds

from datetime import datetime
dt = datetime.today()  # Get timezone naive now
seconds = dt.timestamp()
Posted by: Guest on April-07-2021
-1

Python3 seconds to datetime

>>> from datetime import datetime
>>> datetime.fromtimestamp(1485714600).strftime("%A, %B %d, %Y %I:%M:%S")
'Sunday, January 29, 2017 08:30:00'
Posted by: Guest on May-19-2021

Code answers related to "from seconds to date python"

Python Answers by Framework

Browse Popular Code Answers by Language