473,811 Members | 3,402 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 5459
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
5066
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
3760
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
6923
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
1600
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
2425
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
1929
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
28455
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
8917
by: Francesco | last post by:
I search a function to calculate microseconds in a time istant
0
9605
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10384
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...
1
10395
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10130
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
9204
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...
1
7667
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5553
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...
2
3865
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
3017
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.