时间戳与时间之间的转换,需要一个中间过程,即将先将时间或时间戳先转为时间元组!

1、时间转时间戳:

import datetime, time
s = datetime.datetime(2016,6,22)
time.mktime(s.timetuple()) # 1466524800.0

2、时间戳转时间:

timeTuple = time.localtime(1466524800.0)
time.strftime('%Y-%m-%d', timeTuple) # '2016-06-22'

3、时间元组:共有9个元素,struct_time方式表示,如:

>>> time.localtime()
time.struct_time(tm_year=2012, tm_mon=6, tm_mday=22, tm_hour=12, tm_min=5, tm_sec=49, tm_wday=4, tm_yday=174, tm_isdst=0)

1)time.localtime([secs]):将一个时间戳转换为当前时区的struct_time,参数未提供则以当前时间为准。

2)time.gmtime([secs]):和localtime()方法类似,将一个时间戳转换为UTC时区(0时区)的struct_time。

python 时间和时间戳的转化的更多相关文章

  1. python 时间字符串与日期转化

    python 时间字符串与日期转化 datetime.datetime.strptime(string, format) 根据指定的格式解析字符串为一个datetime类型.相当于datetime.d ...

  2. python—时间与时间戳之间的转换

    python-时间与时间戳之间的转换 对于时间数据,如2016-05-05 20:28:54,有时需要与时间戳进行相互的运算,此时就需要对两种形式进行转换,在Python中,转换时需要用到time模块 ...

  3. Python时间和时间戳互相转换

    # 将时间变成时间戳 def tranftimestamp(stringtime): try: return time.mktime(time.strptime(stringtime, "% ...

  4. Python时间,日期,时间戳之间转换,时间转换时间戳,Python时间戳转换时间,Python时间转换时间戳

    #1.将字符串的时间转换为时间戳方法: a = "2013-10-10 23:40:00" #将其转换为时间数组 import time timeArray = time.strp ...

  5. python 时间与时间戳之间的转换

    https://blog.csdn.net/kl28978113/article/details/79271518 对于时间数据,如2016-05-05 20:28:54,有时需要与时间戳进行相互的运 ...

  6. python 时间和时间戳的转换

    对于时间数据,如2016-05-05 20:28:54,有时需要与时间戳进行相互的运算,此时就需要对两种形式进行转换,在Python中,转换时需要用到time模块,具体的操作有如下的几种: 将时间转换 ...

  7. iOS 时间和时间戳之间转化

    以毫秒为整数值的时间戳转换 时间戳转化为时间NSDate - (NSString *)timeWithTimeIntervalString:(NSString *)timeString { // 格式 ...

  8. python——时间与时间戳之间的转换

    http://blog.csdn.net/google19890102/article/details/51355282

  9. utc时间、本地时间及时间戳转化

    1.时间戳的概念 时间戳的定义请看百科unix时间戳,需要注意的时间戳为当前时刻减去UTC时间(1970.1.1)零点时刻的秒数差,与当前系统所处的时区无关,同一时刻不管在任何时区下得到的时间戳都是一 ...

随机推荐

  1. [转]asp.net5中使用NLog进行日志记录

    本文转自:http://www.cnblogs.com/sguozeng/articles/4861303.html asp.net5中使用NLog进行日志记录 asp.net5中提供了性能强大的日志 ...

  2. Node.js学习笔记(二) --- CommonJs和Nodejs 中自定义模块

    一. 什么是 CommonJs? JavaScript 是一个强大面向对象语言,它有很多快速高效的解释器. 然而, JavaScript标准定义的 API 是为了构建基于浏览器的应用程序.并没有制定一 ...

  3. python中的单例模式的应用

    1 使用__new__方法 class Singleton(object):    def __new__(cls, *args, **kw):        if not hasattr(cls, ...

  4. 简单的java使用SAX解析xml

    1.新建一个SAXTest类,继承import org.xml.sax.helpers.DefaultHandler类 package com.qiao.SrpingSource; import or ...

  5. cocos-creator 脚本逻辑-2

    1.预制体 1)节点操作 Cc.find(‘node-1’) 获取节点 全局事件 作用于 canvas this.node.destroy() 删除节点(从内存中删除) 添加删除获取节点或组件 let ...

  6. HTML 发表说说 制作方法

    ==================================================================================================== ...

  7. Windows API编程----枚举系统进程

    1.该函数可以检索系统中的每个进程的标识符(进程ID) BOOL WINAPI EnumProcesses( _Out_ DWORD *pProcessIds, _In_  DWORD cb, _Ou ...

  8. 申请单位iOS开发者账号

    没有AppleID的需要先申请:此处略过: 1.登录苹果开发者官网(https://developer.apple.com),网速比较慢,多试几次 2. 点击 Enroll 切换到 简体中文 我以下述 ...

  9. Maven 安装与使用(一)

    1. 安装 参考:http://maven.apache.org/install.html A. win7环境下,官网下载maven安装文件 B. 解压缩maven文件 C. 确认已配置好JAVA环境 ...

  10. Linux 学习笔记之关机问题

    在linux领域内大多用在服务器上,很少遇到关机的操作. 正确的关机流程为:sync > shutdown > reboot > halt 关机指令为:shutdown ,你可以ma ...