【问题标题】:Python: Convert unicode string to MM/DD/YYYYPython:将 unicode 字符串转换为 MM/DD/YYYY
【发布时间】:2012-04-10 20:41:50
【问题描述】:

我有一个 unicode 字符串,例如 u'Mar232012'。我想以后期高效可靠的方式使用 python 将其转换为格式 MM/DD/YYYY。

【问题讨论】:

    标签: python datetime converter


    【解决方案1】:
    import datetime
    
    datetime.datetime.strptime(u'Mar232012', '%b%d%Y').strftime('%m/%d/%Y')
    

    打印'03/23/2012'

    【讨论】:

    • @_eumiro 那仍然是一个字符串,不是吗?这些日期可以排序吗?
    猜你喜欢
    • 1970-01-01
    • 2013-06-30
    • 2018-05-19
    • 2019-01-26
    • 1970-01-01
    • 2014-04-24
    • 2017-08-03
    • 2017-05-30
    • 1970-01-01
    相关资源
    最近更新 更多