Using a Unicode format for Python's `time.strftime()`

前端 未结 3 948
有刺的猬
有刺的猬 2020-12-24 09:09

I am trying to call Python\'s time.strftime() function using a Unicode format string:

u\'%d\\u200f/%m\\u200f/%Y %H:%M:%S\'

(\\

3条回答
  •  慢半拍i
    慢半拍i (楼主)
    2020-12-24 09:40

    Many standard library functions still don't support Unicode the way they should. You can use this workaround:

    import time
    my_format = u'%d\u200f/%m\u200f/%Y %H:%M:%S'
    my_time   = time.localtime()
    time.strftime(my_format.encode('utf-8'), my_time).decode('utf-8')
    

提交回复
热议问题