Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #67777
| Path | csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!news.mixmin.net!feeds.phibee-telecom.net!newsfeed.xs4all.nl!newsfeed2a.news.xs4all.nl!xs4all!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail |
|---|---|
| Return-Path | <ikorot01@gmail.com> |
| X-Original-To | python-list@python.org |
| Delivered-To | python-list@mail.python.org |
| X-Spam-Status | OK 0.001 |
| X-Spam-Evidence | '*H*': 1.00; '*S*': 0.00; 'python.': 0.02; 'mrab': 0.05; 'applicable,': 0.07; 'error:': 0.07; 'string': 0.09; '1000.': 0.09; 'formatting': 0.09; 'happen,': 0.09; 'lawrence': 0.09; 'method,': 0.09; 'python': 0.11; 'question.': 0.14; 'digits.': 0.16; 'igor': 0.16; 'integer.': 0.16; 'mark,': 0.16; 'nearest': 0.16; 'precision.': 0.16; 'seconds,': 0.16; 'timestamp': 0.16; 'truncate': 0.16; 'wrote:': 0.18; 'all,': 0.19; 'trying': 0.19; 'properly': 0.19; 'value.': 0.19; '(the': 0.22; 'import': 0.22; 'to:name:python-list@python.org': 0.22; 'error': 0.23; 'format,': 0.24; 'looks': 0.24; 'question': 0.24; 'right.': 0.26; 'this:': 0.26; 'asking': 0.27; 'header:In-Reply-To:1': 0.27; 'record': 0.27; 'point': 0.28; 'function': 0.29; 'leave': 0.29; 'related': 0.29; 'message-id:@mail.gmail.com': 0.30; "i'm": 0.30; 'url:mailman': 0.30; 'gives': 0.31; 'code': 0.31; 'getting': 0.31; 'decimal': 0.31; 'object.': 0.31; 'produces': 0.31; 'another': 0.32; 'url:python': 0.33; 'could': 0.34; 'convert': 0.35; 'but': 0.35; 'received:google.com': 0.35; 'google': 0.35; 'there': 0.35; 'dates': 0.36; 'described': 0.36; 'url:listinfo': 0.36; "i'll": 0.36; 'possible': 0.36; 'hi,': 0.36; 'url:org': 0.36; 'should': 0.36; 'seconds': 0.37; 'too': 0.37; 'expected': 0.38; 'thank': 0.38; 'to:addr:python-list': 0.38; 'files': 0.38; 'pm,': 0.38; 'rather': 0.38; 'does': 0.39; 'environment.': 0.39; 'to:addr:python.org': 0.39; 'url:mail': 0.40; 'how': 0.40; 'remove': 0.60; 'read': 0.60; 'easy': 0.60; 'range': 0.61; 'first': 0.61; 'you.': 0.62; 'provide': 0.64; 'different': 0.65; 'mar': 0.68; 'cut': 0.74; 'milliseconds': 0.84; 'stamp': 0.91 |
| DKIM-Signature | v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :content-type; bh=XOJY1tN1zLqoQQbqtwkNy1wDgUINiIrmXTaslKEbZpI=; b=bPUxmVfsv5Clgx563Ja7FI3m5gbaKPRNGhB47k5hG46IChHyi8sPTVInHx/5K4JjaU OtlnzKEDjh2XSs1zYpEeRxEMfR0q/lXOlnjIc2ebB+fl9LLHuJ4UPBwitQ6M9oZGfgD1 foD51C567KatO8qeY5OSpIgGdS7c8z0rzMOHeYUGY/7X2wx1+KAvodmzATrTllseRFg3 D+DR6cTpHnJ97GcsrpChhDB463uy7Wf3AhTtLlsIV1XH01QrAN42ds82RCtBCx8foadj 9LD+/bn/XttOtUvcrnWANJ8woGNWG7ccJA1FadOzewG1Nzjd4+cade0EiygnFuWbKxcv XpEQ== |
| MIME-Version | 1.0 |
| X-Received | by 10.58.170.69 with SMTP id ak5mr53064vec.28.1393985988989; Tue, 04 Mar 2014 18:19:48 -0800 (PST) |
| In-Reply-To | <5316730B.3080706@mrabarnett.plus.com> |
| References | <CA+FnnTy2zoJYzx+ExkHf8SsENppBLaQzp2zOC9WFYsLBYwK9Qg@mail.gmail.com> <lf5hes$ve3$1@ger.gmane.org> <CA+FnnTxuiNTeaTu7LEdPWvsSnbbirgXqaCS67p5HOrruQPcZ9A@mail.gmail.com> <5316730B.3080706@mrabarnett.plus.com> |
| Date | Tue, 4 Mar 2014 18:19:48 -0800 |
| Subject | Re: Proper conversion of timestamp |
| From | Igor Korot <ikorot01@gmail.com> |
| To | "python-list@python.org" <python-list@python.org> |
| Content-Type | text/plain; charset=ISO-8859-1 |
| X-BeenThere | python-list@python.org |
| X-Mailman-Version | 2.1.15 |
| Precedence | list |
| List-Id | General discussion list for the Python programming language <python-list.python.org> |
| List-Unsubscribe | <https://mail.python.org/mailman/options/python-list>, <mailto:python-list-request@python.org?subject=unsubscribe> |
| List-Archive | <http://mail.python.org/pipermail/python-list/> |
| List-Post | <mailto:python-list@python.org> |
| List-Help | <mailto:python-list-request@python.org?subject=help> |
| List-Subscribe | <https://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe> |
| Newsgroups | comp.lang.python |
| Message-ID | <mailman.7782.1393985991.18130.python-list@python.org> (permalink) |
| Lines | 106 |
| NNTP-Posting-Host | 2001:888:2000:d::a6 |
| X-Trace | 1393985991 news.xs4all.nl 2937 [2001:888:2000:d::a6]:52749 |
| X-Complaints-To | abuse@xs4all.nl |
| Xref | csiph.com comp.lang.python:67777 |
Show key headers only | View raw
MRAB, On Tue, Mar 4, 2014 at 4:42 PM, MRAB <python@mrabarnett.plus.com> wrote: > On 2014-03-04 21:55, Igor Korot wrote: >> >> Hi, Mark, >> >> >> On Tue, Mar 4, 2014 at 1:44 PM, Mark Lawrence <breamoreboy@yahoo.co.uk >> <mailto:breamoreboy@yahoo.co.uk>> wrote: >> >> On 04/03/2014 20:57, Igor Korot wrote: >> >> Hi, ALL, >> I'm getting this: >> >> timestamp out of range for platform localtime()/gmtime() function >> >> trying to convert the timestamp with milliseconds into the >> datetime object. >> >> The first hit of Google gives me this: >> >> >> http://stackoverflow.com/__questions/12458595/convert-__epoch-timestamp-in-python >> >> >> <http://stackoverflow.com/questions/12458595/convert-epoch-timestamp-in-python> >> >> but the solution described is not good for me since it does not >> gives >> me the milliseconds value. >> >> How do I get the proper datetime value including milliseconds >> from the >> timestamp? >> >> Thank you. >> >> >> You have a long record of asking timestamp related questions so you >> should know where the docs are that provide the answer to this >> question. I'll leave you to go off and read them. If you don't >> understand them, please cut and paste your code here, state what you >> expected to happen, what actually happened, including any traceback >> if applicable, and then we'll be happy to point you the error of >> your ways. >> >> >> Working with the dates is not that easy and not just in Python. >> There are too many different formatting involved with many different >> representation. >> And on top of it it is possible to use one system in completely >> different environment. >> >> But this particular question is easy. >> >> What I have is a timestamp which reads: 1289410678L. >> > That's an integer. It looks like the timestamp is a whole number of > seconds, so the number of milliseconds is 0. (I make it '2010-11-10 > 17:37:58'.) Well it is this particular timestamp. But I have a lot of files to process and some do have a timestamp with the milliseconds. > > >> 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. >> >> This is because this timestamp is not in seconds, but rather in >> milliseconds. >> >> Now the question I have is: how do I properly convert this timestamp >> into the datetime object with the milliseconds? >> > Using the datetime's .strftime method, you can include the number of > microseconds in the format with '%f' (it'll write the microseconds as 6 > digits). > > If you want it to the nearest millisecond (the timestamp would be a > float), you could round the timestamp to 3 decimal places, use the '%f' > in the format, and then truncate the string result to remove the last 3 > digits. Right. The question is: how to get the number of milliseconds out of timestamp? Once again: I can get the datetime object with the seconds precision by dividing it on 1000. But that will produce the datetime object with the seconds precision. I can actually produce another timestamp with the milliseconds from a different file... Thank you. > > -- > https://mail.python.org/mailman/listinfo/python-list
Back to comp.lang.python | Previous | Next | Find similar | Unroll thread
Re: Proper conversion of timestamp Igor Korot <ikorot01@gmail.com> - 2014-03-04 18:19 -0800
csiph-web