Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #67791
| From | Gregory Ewing <greg.ewing@canterbury.ac.nz> |
|---|---|
| Newsgroups | comp.lang.python |
| Subject | Re: Proper conversion of timestamp |
| Date | 2014-03-05 17:06 +1300 |
| Message-ID | <bnnm6oFgcj1U1@mid.individual.net> (permalink) |
| References | <CA+FnnTy2zoJYzx+ExkHf8SsENppBLaQzp2zOC9WFYsLBYwK9Qg@mail.gmail.com> <lf5hes$ve3$1@ger.gmane.org> <mailman.7750.1393970120.18130.python-list@python.org> |
Igor Korot wrote:
> What I have is a timestamp which reads: 1289410678L.
>
> Trying to convert this into the datetime object in Python using:
>
> import datetime
> datetime.datetime.fromtimestamp( stamp )
>
> produces the error: timestamp out of range for platform
> localtime()/gmtime() function.
Divide the timestamp by 1000.0 to give floating point
seconds, and then use datetime.fromtimestamp().
>>> d = datetime.datetime.fromtimestamp(1289410678 / 1000.0)
>>> d
datetime.datetime(1970, 1, 16, 10, 10, 10, 678000)
>>> d.strftime("%Y-%m-%d-%H:%M:%S.%f")[:-3]
'1970-01-16-10:10:10.678'
--
Greg
Back to comp.lang.python | Previous | Next — Previous in thread | Find similar | Unroll thread
Re: Proper conversion of timestamp Igor Korot <ikorot01@gmail.com> - 2014-03-04 13:55 -0800 Re: Proper conversion of timestamp Gregory Ewing <greg.ewing@canterbury.ac.nz> - 2014-03-05 17:06 +1300
csiph-web