How to convert a time to a string

前端 未结 3 1627
暖寄归人
暖寄归人 2020-12-04 04:23

I am using the date time lib to get the current date. After obtaining the current date I need to convert the obtained date to in to a string format. Any help is appriciated

相关标签:
3条回答
  • 2020-12-04 04:42
    stringDate = str(today)
    

    If that's what you want.

    0 讨论(0)
  • 2020-12-04 05:00

    datetime.strftime allows you to format a datetime however you want

    0 讨论(0)
  • 2020-12-04 05:01

    You can use today.strftime(format). format will be a string as described here http://docs.python.org/library/time.html#time.strftime . Example:

    from datetime import date
    today = date.today()
    today.strftime("%x")
    #>>> '01/31/11'
    
    0 讨论(0)
提交回复
热议问题