By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
439,941 Members | 1,789 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 439,941 IT Pros & Developers. It's quick & easy.

datetime in microseconds

P: n/a
Hi I have a time in microseconds, for example 0x8C905CBA7F84AF4. I
want this to a normal view in hh:mm:ss DD:MM:YYYY. I tried with
datetime, but it only takes a max of 1000000 microseconds is there
another solution?

Aug 20 '07 #1
Share this Question
Share on Google+
5 Replies


P: n/a
On Aug 20, 6:52 am, mroelo...@gmail.com wrote:
Hi I have a time in microseconds, for example 0x8C905CBA7F84AF4. I
want this to a normal view in hh:mm:ss DD:MM:YYYY. I tried with
datetime, but it only takes a max of 1000000 microseconds is there
another solution?
Just truncate the value so that it's less than 1000000. A slight
difference of a couple seconds shouldn't matter for the output format
you're talking about.

Mike

Aug 20 '07 #2

P: n/a
On Aug 20, 9:52 pm, mroelo...@gmail.com wrote:
Hi I have a time in microseconds, for example 0x8C905CBA7F84AF4. I
want this to a normal view in hh:mm:ss DD:MM:YYYY. I tried with
datetime, but it only takes a max of 1000000 microseconds is there
another solution?
Your question can be interpreted in two possible ways:

1. You have an interval or duration (independent of a calendar point)
and you want to express it in years, months, days, hours, etc. This is
not possible, due to the variable number of days in a month. The best
that you can do is express it as days, hours, etc.
>>microsecs = 0x8C905CBA7F84AF4
secs = microsecs // 1000000 # or round to nearest if you prefer
mins, secs = divmod(secs, 60)
hrs, mins = divmod(mins, 60)
days, hrs = divmod(hrs, 24)
days, hrs, mins, secs
(7326893L, 11L, 1L, 16L)
>>>
2. You want to know the (Gregorian) calendar point that is
0x8C905CBA7F84AF4 microseconds after some epoch. In this case you need
to specify what the epoch is. Then you can try something like:
>>datetime.datetime.fromordinal(1) + datetime.timedelta(microseconds=microsecs
)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
OverflowError: date value out of range
>># Whoops!
years_approx = days / 365.25
years_approx
20059.939767282682
>>>
Hmmm, one of us seems to be missing something ...

Aug 20 '07 #3

P: n/a
On Aug 20, 3:15 pm, John Machin <sjmac...@lexicon.netwrote:
On Aug 20, 9:52 pm, mroelo...@gmail.com wrote:
Hi I have a time in microseconds, for example 0x8C905CBA7F84AF4. I
want this to a normal view in hh:mm:ss DD:MM:YYYY. I tried with
datetime, but it only takes a max of 1000000 microseconds is there
another solution?

Your question can be interpreted in two possible ways:

1. You have an interval or duration (independent of a calendar point)
and you want to express it in years, months, days, hours, etc. This is
not possible, due to the variable number of days in a month. The best
that you can do is express it as days, hours, etc.
>microsecs = 0x8C905CBA7F84AF4
secs = microsecs // 1000000 # or round to nearest if you prefer
mins, secs = divmod(secs, 60)
hrs, mins = divmod(mins, 60)
days, hrs = divmod(hrs, 24)
days, hrs, mins, secs

(7326893L, 11L, 1L, 16L)

2. You want to know the (Gregorian) calendar point that is
0x8C905CBA7F84AF4 microseconds after some epoch. In this case you need
to specify what the epoch is. Then you can try something like:
>datetime.datetime.fromordinal(1) + datetime.timedelta(microseconds=microsecs

)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
OverflowError: date value out of range
># Whoops!
years_approx = days / 365.25
years_approx
20059.939767282682

Hmmm, one of us seems to be missing something ...
Sorry, sorry, sorry it was the wrong value, it should be
0xE0E6FAC3FF3AB2.

Aug 20 '07 #4

P: n/a
On Aug 20, 4:17 pm, mroelo...@gmail.com wrote:
On Aug 20, 3:15 pm, John Machin <sjmac...@lexicon.netwrote:
On Aug 20, 9:52 pm, mroelo...@gmail.com wrote:
Hi I have a time in microseconds, for example 0x8C905CBA7F84AF4. I
want this to a normal view in hh:mm:ss DD:MM:YYYY. I tried with
datetime, but it only takes a max of 1000000 microseconds is there
another solution?
Your question can be interpreted in two possible ways:
1. You have an interval or duration (independent of a calendar point)
and you want to express it in years, months, days, hours, etc. This is
not possible, due to the variable number of days in a month. The best
that you can do is express it as days, hours, etc.
>>microsecs = 0x8C905CBA7F84AF4
>>secs = microsecs // 1000000 # or round to nearest if you prefer
>>mins, secs = divmod(secs, 60)
>>hrs, mins = divmod(mins, 60)
>>days, hrs = divmod(hrs, 24)
>>days, hrs, mins, secs
(7326893L, 11L, 1L, 16L)
2. You want to know the (Gregorian) calendar point that is
0x8C905CBA7F84AF4 microseconds after some epoch. In this case you need
to specify what the epoch is. Then you can try something like:
>>datetime.datetime.fromordinal(1) + datetime.timedelta(microseconds=microsecs
)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
OverflowError: date value out of range
>># Whoops!
>>years_approx = days / 365.25
>>years_approx
20059.939767282682
Hmmm, one of us seems to be missing something ...

Sorry, sorry, sorry it was the wrong value, it should be
0xE0E6FAC3FF3AB2.
The solution I made, with thanks to John. Maybe someone a better one??
def DecodeDateTime(self,dateTime):
dateTime = self.Rotate(dateTime)
microsecs = int(hexlify(dateTime),16)
microsecs -= 31536000000000 # -1 Year
microsecs -= 1123200000000 # -13 Days (magic?)
secs = microsecs // 1000000
mins, secs = divmod(secs, 60)
hrs, mins = divmod(mins, 60)
days, hrs = divmod(hrs, 24)
timed = datetime.datetime.fromordinal(1) +
datetime.timedelta(days)
return "%02d-%02d-%02d %02d:%02d:%02d"%(timed.day,
timed.month, timed.year, hrs, mins, secs)

Aug 20 '07 #5

P: n/a
Robert Dailey wrote:
A small off topic question. Why use divmod() instead of the modulus
operator?
Because he needed both the quotient and the remainder. % only gives you the
remainder.

--
Robert Kern

"I have come to believe that the whole world is an enigma, a harmless enigma
that is made terrible by our own mad attempt to interpret it as though it had
an underlying truth."
-- Umberto Eco

Aug 20 '07 #6

This discussion thread is closed

Replies have been disabled for this discussion.