“Python Timedelta” Code-Antworten

Python Timedelta

import datetime

today = datetime.date.today()

next_week = today + datetime.timedelta(days=7)
Puzzled Penguin

Python Strftime ISO 8601

>>> # convert string in iso 8601 date dime format to python datetime type
>>> import datetime
>>> datetime.datetime.strptime('2020-06-19T15:52:50Z', "%Y-%m-%dT%H:%M:%SZ")
datetime.datetime(2020, 6, 19, 15, 52, 50)
Cheerful Constrictor

Python Timedelta

from datetime import timedelta
# Create a delta time
datetime_delta = timedelta(weeks = 1, days = 2, hours = 4, minutes = 10,
                           seconds = 8, milliseconds = 25, microseconds = 8)
print("Delta datetime :- ", datetime_delta)
>>> Delta datetime :-  9 days, 4:10:08.025008
Intempestive Al Dente

DateTime Year Python

import datetime
now = datetime.datetime.now()
print(now.year, now.month, now.day, now.hour, now.minute, now.second)
miletoo

Datum. Monate Datum Uhrzeit

import datetime
dt = datetime.datetime.today()
print dt.year
# Output: 2016

print dt.month
# Output: 8

print dt.day
# Output: 22
Fair Frog

Format Timedelta Python

def strfdelta(tdelta, fmt):
    d = {"days": tdelta.days}
    d["hours"], rem = divmod(tdelta.seconds, 3600)
    d["minutes"], d["seconds"] = divmod(rem, 60)
    return fmt.format(**d)
Busy Boar

Ähnliche Antworten wie “Python Timedelta”

Fragen ähnlich wie “Python Timedelta”

Weitere verwandte Antworten zu “Python Timedelta” auf Python

Durchsuchen Sie beliebte Code-Antworten nach Sprache

Durchsuchen Sie andere Codesprachen