zoukankan      html  css  js  c++  java
  • python 时间戳和日期相互转换

    当前时间戳:time.time()
    当前日期:time.ctime()
    1、Python下日期到时间戳的转换
    import datetime
    import time
    dateC=datetime.datetime(2010,6,6,8,14,59)
    timestamp=time.mktime(dateC.timetuple())
    print timestamp
     
    2、Python下将时间戳转换到日期
    import datetime
    import time
    ltime=time.localtime(1395025933)
    timeStr=time.strftime("%Y-%m-%d %H:%M:%S", ltime)
    print timeStr
     
    3、将前端传过来的时间字符串转为时间戳
     
    import time
    a = "2011-09-28 10:00:00"
    time.mktime(time.strptime(a,'%Y-%m-%d %H:%M:%S')) #结果 1317175200

    4、备注
    """
    localtime([seconds]) -> (tm_year,tm_mon,tm_mday,tm_hour,tm_min,
    tm_sec,tm_wday,tm_yday,tm_isdst)

    Convert seconds since the Epoch to a time tuple expressing local time.
    When 'seconds' is not passed in, convert the current time instead.
    """
    """
    strftime(format[, tuple]) -> string

    Convert a time tuple to a string according to a format specification.
    See the library reference manual for formatting codes. When the time tuple
    is not present, current time as returned by localtime() is used.
    """
  • 相关阅读:
    iOS开发 当前时间 时间戳 转换
    iOS开发 下滑隐藏Tabbar
    iOS开发 浅见runloop
    iOS开发 检测版本更新
    IOS开发 二维码功能的实现
    级数
    算法-快速排序
    struts2.0中struts.xml配置文件详解【转】
    javascript原型【转】
    AOP各种的实现【转】
  • 原文地址:https://www.cnblogs.com/lazyboy1/p/5126771.html
Copyright © 2011-2022 走看看