python时间戳和时间字符串的各种转换

    科技2024-11-04  12

    时间转时间戳

    import time str_time="2010--03--24 20:47:31" timeStamp=int(time.mktime(time.strptime(str_time,"%Y--%m--%d %H:%M:%S"))) print(timeStamp)

    结果是1269434851

    时间戳转时间字符串

    timeStamp=1269434851 str_time=time.strftime("%Y--%m--%d %H:%M:%S", time.localtime(timeStamp)) print(str_time)

    结果为2010–03–24 20:47:31

    Processed: 0.027, SQL: 8