PyDocs

Nav

Data Types

time

  • time(hour=0, minute=0, second=0, microsecond=0, tzinfo=None, *, fold=0)
Time with time zone.

All arguments are optional. tzinfo may be None, or an instance of
a tzinfo subclass. The remaining arguments may be ints.
Members of time

_

__format__
Formats self with strftime.
__str__
Return str(self).

d

dst
Return self.tzinfo.dst(self).

f

fold
In [0, 1].
fromisoformat
Construct a time from a string in ISO 8601 format.

h

hour
In range(24).

i

isoformat
Return the time formatted according to ISO.

m

max
The latest representable time, time(23, 59, 59, 999999).
microsecond
In range(1000000).
min
The earliest representable time, time(0, 0, 0, 0).
minute
In range(60).

r

replace
Return time with new specified fields.
resolution
The smallest possible difference between non-equal time objects, timedelta(microseconds=1), although note that arithmetic on time objects is not supported.

s

second
In range(60).
strftime
Format using strftime().
strptime
Parse string according to the given time format (like time.strptime()).

t

tzinfo
The object passed as the tzinfo argument to the time constructor, or None if none was passed.
tzname
Return self.tzinfo.tzname(self).

u

utcoffset
Return self.tzinfo.utcoffset(self).
1 Example
>>> import datetime as dt

>>> # Using datetime.combine()
>>> d = dt.date(2005, 7, 14)
>>> t = dt.time(12, 30)
>>> dt.datetime.combine(d, t)
datetime.datetime(2005, 7, 14, 12, 30)

>>> # Using datetime.now()
>>> dt.datetime.now()
datetime.datetime(2007, 12, 6, 16, 29, 43, 79043)   # GMT +1
>>> dt.datetime.now(dt.timezone.utc)
datetime.datetime(2007, 12, 6, 15, 29, 43, 79060, tzinfo=datetime.timezone.utc)

>>> # Using datetime.strptime()
>>> my_datetime = dt.datetime.strptime("21/11/06 16:30", "%d/%m/%y %H:%M")
>>> my_datetime
datetime.datetime(2006, 11, 21, 16, 30)

>>> # Using datetime.timetuple() to get tuple of all attributes
>>> tt = my_datetime.timetuple()
>>> for it in tt:
...     print(it)
...
2006    # year
11      # month
21      # day
16      # hour
30      # minute
0       # second
1       # weekday (0 = Monday)
325     # number of days since 1st January
-1      # dst - method tzinfo.dst() returned None

>>> # Date in ISO format
>>> ic = my_datetime.isocalendar()
>>> for it in ic:
...     print(it)
...
2006    # ISO year
47      # ISO week
2       # ISO weekday

>>> # Formatting a datetime
>>> my_datetime.strftime("%A, %d. %B %Y %I:%M%p")
'Tuesday, 21. November 2006 04:30PM'
>>> 'The {1} is {0:%d}, the {2} is {0:%B}, the {3} is {0:%I:%M%p}.'.format(my_datetime, "day", "month", "time")
'The day is 21, the month is November, the time is 04:30PM.'
from the Python docs
See Also
No see-alsos for datetime/time
0 Notes
No notes for time