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.
    """
  • 相关阅读:
    转:每个架构师都应该研究下康威定律
    使用OpenShiftFQ上外网
    关系模式设计
    数据库应用系统工程过程
    数据库系统
    四种常见 Git 工作流比较
    Git 进阶指南
    C#高性能TCP服务的多种实现方式
    浮动广告
    <span></span>
  • 原文地址:https://www.cnblogs.com/lazyboy1/p/5126771.html
Copyright © 2011-2022 走看看