473,699 Members | 2,628 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

datetime in microseconds

Hi I have a time in microseconds, for example 0x8C905CBA7F84A F4. 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
5 5447
On Aug 20, 6:52 am, mroelo...@gmail .com wrote:
Hi I have a time in microseconds, for example 0x8C905CBA7F84A F4. 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
On Aug 20, 9:52 pm, mroelo...@gmail .com wrote:
Hi I have a time in microseconds, for example 0x8C905CBA7F84A F4. 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 = 0x8C905CBA7F84A F4
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
0x8C905CBA7F84A F4 microseconds after some epoch. In this case you need
to specify what the epoch is. Then you can try something like:
>>datetime.date time.fromordina l(1) + datetime.timede lta(microsecond s=microsecs
)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
OverflowError: date value out of range
>># Whoops!
years_appro x = days / 365.25
years_appro x
20059.939767282 682
>>>
Hmmm, one of us seems to be missing something ...

Aug 20 '07 #3
On Aug 20, 3:15 pm, John Machin <sjmac...@lexic on.netwrote:
On Aug 20, 9:52 pm, mroelo...@gmail .com wrote:
Hi I have a time in microseconds, for example 0x8C905CBA7F84A F4. 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 = 0x8C905CBA7F84A F4
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
0x8C905CBA7F84A F4 microseconds after some epoch. In this case you need
to specify what the epoch is. Then you can try something like:
>datetime.datet ime.fromordinal (1) + datetime.timede lta(microsecond s=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.939767282 682

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

Aug 20 '07 #4
On Aug 20, 4:17 pm, mroelo...@gmail .com wrote:
On Aug 20, 3:15 pm, John Machin <sjmac...@lexic on.netwrote:
On Aug 20, 9:52 pm, mroelo...@gmail .com wrote:
Hi I have a time in microseconds, for example 0x8C905CBA7F84A F4. 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 = 0x8C905CBA7F84A F4
>>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
0x8C905CBA7F84A F4 microseconds after some epoch. In this case you need
to specify what the epoch is. Then you can try something like:
>>datetime.date time.fromordina l(1) + datetime.timede lta(microsecond s=microsecs
)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
OverflowError: date value out of range
>># Whoops!
>>years_appro x = days / 365.25
>>years_appro x
20059.939767282 682
Hmmm, one of us seems to be missing something ...

Sorry, sorry, sorry it was the wrong value, it should be
0xE0E6FAC3FF3AB 2.
The solution I made, with thanks to John. Maybe someone a better one??
def DecodeDateTime( self,dateTime):
dateTime = self.Rotate(dat eTime)
microsecs = int(hexlify(dat eTime),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.dateti me.fromordinal( 1) +
datetime.timede lta(days)
return "%02d-%02d-%02d %02d:%02d:%02d" %(timed.day,
timed.month, timed.year, hrs, mins, secs)

Aug 20 '07 #5
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
5058
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. -- >> ¥xÆW¬ì¤j¸ê¤u¨t ²M¬y¯¸ # ntust.org #
2
3752
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 import xml.utils.iso8601
2
733
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 in our image generators are updated by this dynamics application, and we need to update them at the rate they are being refreshed so that we don't get any stutter from frames being used twice or having to be thrown out. Without microsecond...
2
6914
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 to direct insert and select seconds_from _Epoch seconds_from _Epoch (period) microseconds_part seconds_from _Epochmicroseconds_part without some data conversion ?
0
1594
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 to direct insert and select seconds_from _Epoch seconds_from _Epoch (period) microseconds_part seconds_from _Epoch(no period here)microseconds_part without some data conversion ?
5
2418
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 time.time <==> datetime.utcfromtimestamp will cause problems come 2038. Unfortunately there don't seem to be "fromstring" equivalents for datetime.ctime or datetime.isoformat. Ideally the serialized datetime should be human readable, and
4
1920
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, 765000) Thank you for help L.
5
28448
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) bb=datetime.datetime(2006, 8, 3, 17, 59, 36, 46000) so c=bb-aa will be datetime.timedelta(5, 6339, 437000)
3
8912
by: Francesco | last post by:
I search a function to calculate microseconds in a time istant
0
8704
marktang
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9192
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
9054
jinu1996
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
8895
tracyyun
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
7781
agi2029
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
5879
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4390
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4637
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3071
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 we have to send another system

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.