代码如下:

def timestamp_datetime(value):

    format = '%Y-%m-%d %H:%M:%S'
    # value为传入的值为时间戳(整形),如:1332888820
    value = time.localtime(value)
    ## 经过localtime转换后变成
    ## time.struct_time(tm_year=2012, tm_mon=3, tm_mday=28, tm_hour=6, tm_min=53, tm_sec=40, tm_wday=2, tm_yday=88, tm_isdst=0)
    # 最后再经过strftime函数转换为正常日期格式。
    dt = time.strftime(format, value)
    return dt
 
 

python处理时间戳的更多相关文章

  1. Python 获取时间戳

    Python 获取时间通过 time 模块 如下代码,是通过获取当前的时间,按照格式输出 Python默认获取当前的时间返回的都是时间的元组,下面是元组的,字符串时间的一个转换输出 # -*- cod ...

  2. 使用python制作时间戳转换工具

    使用python制作时间戳转换工具 python 时间戳转日期 日期转时间戳 前言:作为一个程序员一般情况下,json和时间戳是常用的两个工具,我咨询过很多个朋友,他们一般都是通过在线工具对json进 ...

  3. Python 将时间戳转换为本地时间并进行格式化

    在python中,时间戳默认是为格林威治时间,而我们为东八区 使用localtime() 本地化时间戳 使用 strftime() 格式化时间戳 time = time.strftime('%Y%m% ...

  4. python UTC,时间戳,字符串转换

    #!/usr/bin/env python #_*_coding:utf-8_*_ # 本地时间 转换 为时间戳 import time import pytz import datetime dat ...

  5. 关于Python输出时间戳的问题

    在我们的程序中,有时候想要知道程序的执行时间或者准确的停止时间,这时候就需要我们自己添加一个时间戳,以便我们做出判断和相应的处理. 下面是我亲测并收集的资料,菜鸟一枚,不全之处大神可给予补充和指正. ...

  6. [py]GTM和UTC及python的时间戳

    时间戳是一串字符串 time.time() 时间戳是指格林威治时间1970年01月01日00时00分00秒(北京时间1970年01月01日08时00分00秒)起至现在的总毫秒数.通俗的讲, 时间戳是一 ...

  7. python unix时间戳

    这是第一次用着python感到怒了,从datetime转化到timestamp数值居然没有直接的函数 直接获取当前时间戳倒是方便: import time timestamp = time.time( ...

  8. python转换时间戳和日期时间格式的转换

    [steven@txzxp2 seccenter]$ python Python 2.7.5 (default, Jul  8 2013, 09:48:59)  [GCC 4.8.1 20130603 ...

  9. Python使用时间戳

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

  10. Python 将一个时间戳格式化为(格林威治时间或者本地时区时间)

    时间戳是指格林威治时间1970年01月01日00时00分00秒(北京时间1970年01月01日08时00分00秒)起至现在的总秒数. 获取一个时间戳 import time times = time. ...

随机推荐

  1. 【转】不要使用SBJSON(json-framework)

    原文网址:http://blog.devtang.com/2012/05/05/do-not-use-sbjson/ 不知道为什么,在iOS开发中,有很多人使用 SBJSON (又被称作json-fr ...

  2. Juniper路由器

    Juniper路由器入门之一:需要子接口的端口配置 set interfaces fe-2/0/1 vlan-tagging              ――――在配置接口启用封装VLAN set in ...

  3. HO引擎近况20150422

    这个月到现在才更新主要是想等UI模块中的一个地方攻关下来再更新,但是每天工作到很晚才回家所以一直没弄,上周日弄了一下基本上是通了! 公司的项目如我所料被砍了,又开始了一个新的项目,但是也存在许多问题, ...

  4. F - Dima and Lisa(哥德巴赫猜想)

    Problem description Dima loves representing an odd number as the sum of multiple primes, and Lisa lo ...

  5. 本地sql文件导入mysql数据库

    mysql中配置my.ini interactive_timeout = 120 wait_timeout = 120 max_allowed_packet = 32M 导入sql运行命令 sourc ...

  6. Linux下实现视频读取

    V4L(video4linux是一些视频系统,视频软件.音频软件的基础,经常时候在需要采集图像的场合,如视频监控,webcam,可视电话,经常使用在embedded linux中是linux嵌入式开发 ...

  7. WPF开发“Program '*' does not contain a static 'Main' method suitable for an entry point”错误

    WPF项目编译时出现“Program '*' does not contain a static 'Main' method suitable for an entry point”错误,   解决方 ...

  8. Linker scripts之SECTIONS

    1 Purpose The linker script describes how the sections in the input files should be mapped into the ...

  9. Elasticsearch学习(一)————简单命令

    Elasticsearch一.简介**Elasticsearch 是一个分布式的搜索和分析引擎,可以用于全文检索.结构化检索和分析,并能将这三者结合起来.Elasticsearch 基于 Lucene ...

  10. 反射API提供的常用类和函数

    ReflectionParameter 取回了函数或方法参数的相关信息. {//要自行检查函数的参数,首先创建一个 ReflectionFunction 或 ReflectionMethod 的 实例 ...