`

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

阅读更多

情景:

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

1.在控制台下输入:python

 

[python] view plaincopy
 
  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 plaincopy
 
  1. >>> import time  

 

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

 

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

 

4.print time.ctime(1355028714.92)

 

[python] view plaincopy
 
  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))

分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics