zoukankan      html  css  js  c++  java
  • datetime.datetime.now()时间格式转化是碰到的问题

    import datetime
    
    print datetime.datetime.now()
    
    # 2016-03-28 17:16:00.812000
    
    a = ‘2016-03-28 17:16:00.812000’
    
    timeArray = time.strptime(a, '%Y-%m-%d %H:%M:%S.%f')   ##注意: %f是microseconds的格式化符号。
    
    print timeArray
    
    #time.struct_time(tm_year=2016, tm_mon=3, tm_mday=28, tm_hour=17, tm_min=22, tm_sec=38, tm_wday=0, tm_yday=88, tm_isdst=-1)
    a = datetime.datetime.now()
    print a                                  ## a变量不指向一个字符串对象,而是指向一个datetime.datetime类型的对象
    # 2016-03-28 17:24:52.571000
    timeArray = time.strptime(a, '%Y-%m-%d %H:%M:%S.%f')    ## 所有这里报错。 time.striptime的第一个参数,应该是字符串对象
    
    Traceback (most recent call last):           
      File "<console>", line 1, in <module>
      File "C:Python27lib\_strptime.py", line 467, in _strptime_time
        return _strptime(data_string, format)[0]
      File "C:Python27lib\_strptime.py", line 322, in _strptime
        found = format_regex.match(data_string)
    TypeError: expected string or buffer
  • 相关阅读:
    apio2018题解
    ynoi2018
    hdu2036
    Morley's Theorem
    计算几何
    luogu1355 神秘大三角
    poj2398
    洛谷---小L和小K的NOIP考后放松赛
    LibreOJ β Round #7
    python3
  • 原文地址:https://www.cnblogs.com/haoshine/p/5329862.html
Copyright © 2011-2022 走看看