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? 5 5436
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
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 ...
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.
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)
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 This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: ´_¬¡¤F |
last post by:
I can include time.h and use time() to get UTC seconds,but
how can I get microseconds ??
My OS is windows.
--
[m[1m>> [;33;40m¥x[1mÆW¬ì¤j¸ê¤u¨t ²M¬y[;33;40m¯¸[33m [;31;40m#[1m...
|
by: Samuel |
last post by:
Hello,
I am trying to convert a local time into UTC ISO8601, then parse it
back into local time. I tried the following:
----------------------
#!/usr/bin/python
import time
import datetime...
|
by: Michael Evans |
last post by:
First, we rely on a stable update rate so that our physics and dynamics
calculations and integrations are based on a known interval and
therefore are true-to-life.
Second, the graphics positions...
|
by: In. Martin Prá¹ek |
last post by:
I I read the documentation well (PG 7.3.3 ) , i see that there is not a native support for data type UNIX TIMESTAMP and "unix timestamp expressed as microseconds"
ie there it is impossible...
|
by: NTPT |
last post by:
I read the documentation well (PG 7.3.3 ) , it seems that there is not a native support for data type UNIX TIMESTAMP and "unix timestamp expressedas microseconds"
ie there it is impossible...
| |
by: Brendan |
last post by:
Hi All
I can't find the "Python Way" of writing a datetime instance to a
string so that it can be easily parsed back again. time.strptime is
apparantly not supported on some platforms, and...
|
by: Lad |
last post by:
How can I find days and minutes difference between two datetime
objects?
For example If I have
b=datetime.datetime(2006, 8, 2, 8, 57, 28, 687000)
a=datetime.datetime(2006, 8, 1, 18, 19, 45,...
|
by: Lad |
last post by:
Hello,
what is the best /easest way how to get number of hours and minutes
from a timedelta object?
Let's say we have
aa=datetime.datetime(2006, 7, 29, 16, 13, 56, 609000)...
|
by: Francesco |
last post by:
I search a function to calculate microseconds in a time istant
|
by: Hystou |
last post by:
There are some requirements for setting up RAID:
1. The motherboard and BIOS support RAID configuration.
2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
| |
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
|
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
| |
by: 6302768590 |
last post by:
Hai team
i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
| |