转换距1970年的秒数为可读的时间格式

情景:

程序获得了一个距1970.1.1的秒数,假设为“1355028714.92” 。这个长长的秒数看着是不是有些头大?于是乎就想办法将这个秒数转换成可读的时间格式,当然转换的方法是很多的,下面列出一个比较简单方便的转换方法--通过Python转换。

1.在控制台下输入:python

 

[python]  view plain copy
 
  1. rain:softWare zhaoguangyu$ python  
  2. Python 2.7.2 (default, Jun 20 201216:23:33)   
  3. [GCC 4.2.1 Compatible Apple Clang 4.0 (tags/Apple/clang-418.0.60)] on darwin  
  4. Type "help""copyright""credits" or "license" for more information.  

 

2.导入时间函数:import time

 

[python]  view plain copy
 
  1. >>> import time  

 

3.打印当前距1970的秒数:print time.time()

 

[python]  view plain copy
 
  1. >>> print time.time()  
  2. 1355028714.92  

 

4.print time.ctime(1355028714.92)

 

[python]  view plain copy
 
  1. >>> print time.ctime(1355028714.92)  
  2. Sun Dec  9 12:51:54 2012  

哈 这看起来是不是清晰多了。

 

年月日转为秒数from EPOC

比如下面返回从1970年到2037年12月31日的秒

 time.mktime((2037,12,31,0,0,0,0,0,0))

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值