Go Python format Timestamp __python

Source: Internet
Author: User

All right: Http://docs.python.org/library/datetime.html?highlight=datetime#datetime.tzinfo.


Source: http://hi.baidu.com/mvp_xuan/blog/item/1a34cf0830581b9ed0581b74.html

Antecedent: You need to read a task list on Google's server, and it turns out that the time result for this list is the timestamp (relative to the offset in seconds of 1970.1.1 00:00:00).


The raw processing data is as follows:

"Createtime": "1319425189282", \ n "updatetime": "1319425189282", \ n "accesstime": "1319425189282", \ n

The code is as follows:

——————————————————————————

Import Time

CreateValue = 1319425189282 #以毫秒为单位的时间, starting from 1970 to today
CreateValue = float (createvalue)
CreateValue/= 1000 #除以1000的原因是gmtime这个方法只能转换秒级, and the raw data is milliseconds

print time.gmtime (createvalue)

print time.strftime ('%y-%m-%d%h:%m:%s ', Time.gmtime (CreateValue))

——————————————————————————

Output:

C:\Python26\python.exe c:/users/mvp_xuan/desktop/learnpython/test2.py
Time.struct_time (tm_year=2011, tm_mon=10, tm_mday=24, tm_hour=2, tm_min=59, tm_sec=49, tm_wday=0, tm_yday=297, tm_ isdst=0)
2011-10-24 02:59:49

Process finished with exit code 0

Haha, this can be dealt with this millisecond level of the value.





"slowrate": "%.4f" (Float (r[u "slowrate"))
Round (r[u "Slowrate"],3), 3 means to save several decimal places.


Records =[]
Records.append ({"Channelid": "%s"% (r[u "Channelid"]), "accessdate": "%s"% (r[u "accessdate" "].strftime ("%y%m%d%h%m "))," Slowspeedcount ": Int (r[u" Slowspeedcount "])," slowrate ":"%.4f "(Float (r[u" slowrate "])


To view:
Http://docs.python.org/library/functions.html?highlight=float#float

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.