In [1]:
import datetime

In [2]:
d = datetime.date(2018, 12, 31)

In [3]:
print(d)


2018-12-31

In [4]:
print(type(d))


<class 'datetime.date'>

In [5]:
print(d.isoformat())


2018-12-31

In [6]:
print(type(d.isoformat()))


<class 'str'>

In [7]:
t = datetime.time(5, 0, 30, 1000)

In [8]:
print(t)


05:00:30.001000

In [9]:
print(type(t))


<class 'datetime.time'>

In [10]:
print(t.isoformat())


05:00:30.001000

In [11]:
print(type(t.isoformat()))


<class 'str'>

In [12]:
print(t.isoformat('hours'))


05

In [13]:
print(t.isoformat('minutes'))


05:00

In [14]:
print(t.isoformat('seconds'))


05:00:30

In [15]:
print(t.isoformat('milliseconds'))


05:00:30.001

In [16]:
print(t.isoformat('microseconds'))


05:00:30.001000

In [17]:
dt = datetime.datetime(2018, 12, 31, 5, 0, 30, 1000)

In [18]:
print(dt)


2018-12-31 05:00:30.001000

In [19]:
print(type(dt))


<class 'datetime.datetime'>

In [20]:
print(dt.isoformat())


2018-12-31T05:00:30.001000

In [21]:
print(type(dt.isoformat()))


<class 'str'>

In [22]:
print(dt.isoformat(' '))


2018-12-31 05:00:30.001000

In [23]:
print(dt.isoformat('x'))


2018-12-31x05:00:30.001000

In [24]:
# print(dt.isoformat('xx'))
# TypeError: isoformat() argument 1 must be a unicode character, not str

In [25]:
print(dt.isoformat(timespec='hours'))


2018-12-31T05

In [26]:
print(dt.isoformat(timespec='minutes'))


2018-12-31T05:00

In [27]:
print(dt.isoformat(timespec='seconds'))


2018-12-31T05:00:30

In [28]:
print(dt.isoformat(timespec='milliseconds'))


2018-12-31T05:00:30.001

In [29]:
print(dt.isoformat(timespec='microseconds'))


2018-12-31T05:00:30.001000

In [30]:
print(dt.isoformat(' ', 'seconds'))


2018-12-31 05:00:30

In [31]:
print(dt.date())


2018-12-31

In [32]:
print(type(dt.date()))


<class 'datetime.date'>

In [33]:
print(dt.date().isoformat())


2018-12-31

In [34]:
print(type(dt.date().isoformat()))


<class 'str'>

In [35]:
print(dt.time())


05:00:30.001000

In [36]:
print(type(dt.time()))


<class 'datetime.time'>

In [37]:
print(dt.time().isoformat())


05:00:30.001000

In [38]:
print(type(dt.time().isoformat()))


<class 'str'>

In [39]:
print(dt.time().isoformat('seconds'))


05:00:30