Converting a string to a formatted date-time string using Python

前端 未结 5 1268
予麋鹿
予麋鹿 2020-12-05 07:37

I\'m trying to convert a string \"20091229050936\" into \"05:09 29 December 2009 (UTC)\"

>>>import time
>>>s = time.strptime(\"200912290509         


        
5条回答
  •  时光取名叫无心
    2020-12-05 08:04

    For me this is the best and it works on Google App Engine as well

    Example showing UTC-4

    import datetime   
    UTC_OFFSET = 4
    local_datetime = datetime.datetime.now()
    print (local_datetime - datetime.timedelta(hours=UTC_OFFSET)).strftime("%Y-%m-%d %H:%M:%S")
    

提交回复
热议问题