How to specify date and time in python?

后端 未结 4 1074
自闭症患者
自闭症患者 2021-02-06 23:12

Quite simple newbie question:

What is the object used in python to specify date (and time) in Python?

For instance, to create an object that holds a given date a

4条回答
  •  余生分开走
    2021-02-06 23:24

    >>> import datetime
    >>> datetime.datetime.strptime('05/10/09 18:00', '%d/%m/%y %H:%M')
    datetime.datetime(2009, 10, 5, 18, 0)
    >>> datetime.datetime.today()
    datetime.datetime(2009, 10, 5, 21, 3, 55, 827787)
    

    So, you can either use format string to convert to datetime.datetime object or if you're particularly looking at today's date could use today() function.

提交回复
热议问题