Python-变换距1970年的秒数为可读的时间格式

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

情景:

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

1.在控制台下输入:python

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

2.导入时间函数:import time

>>> import time

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

>>> print time.time()
1355028714.92

4.print time.ctime(1355028714.92)

>>> print time.ctime(1355028714.92)
Sun Dec  9 12:51:54 2012

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