【问题标题】:Convert ctime to unicode and unicode to ctime python将 ctime 转换为 unicode 并将 unicode 转换为 ctime python
【发布时间】:2011-06-12 15:21:10
【问题描述】:

我已将 ctime 值转换为 unicode

1295478503.6789999 到 '2011 年 1 月 19 日星期三 18:08:23'

我可以倒退吗? 从第二行到第一行?

【问题讨论】:

    标签: python unicode ctime


    【解决方案1】:

    您需要 Python 时间模块,特别是 strptime() 函数。 (你是如何从 ctime 转换为 unicode/string 的?可能是 time.strftime()。所以寻找它的反方向是有意义的,即 time.strptime()。)

    这也是一个很好的 Google 查询:http://www.google.com/search?q=python+parse+time+string

    示例:

    entropy:~>python
    Python 2.6.1 (r261:67515, Jun 24 2010, 21:47:49) 
    [GCC 4.2.1 (Apple Inc. build 5646)] on darwin
    Type "help", "copyright", "credits" or "license" for more information.
    >>> import time
    >>> u = u'Wed Jan 19 18:08:23 2011'
    >>> t = time.strptime(u)
    >>> t
    time.struct_time(tm_year=2011, tm_mon=1, tm_mday=19, tm_hour=18, tm_min=8, tm_sec=23, tm_wday=2, tm_yday=19, tm_isdst=-1)
    >>> time.mktime(t)
    1295489303.0
    

    【讨论】:

      【解决方案2】:
      import time
      time.mktime(time.strptime('Wed Jan 19 18:08:23 2011'))
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2023-03-17
        • 2011-12-07
        • 1970-01-01
        • 1970-01-01
        • 2011-10-10
        • 2021-02-04
        • 2021-12-26
        • 2013-05-17
        相关资源
        最近更新 更多