473,662 Members | 2,413 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

time.mktime problem

Hi, on Linux (Fedora FC4) and Python 2.4.1
I am trying to know the time delta in seconds between two times given
in the HHMMSS format. My code looks like:

import datetime, time
ta1=(time.strpt ime('000001', '%H%M%S'))
ta2=(time.strpt ime('230344', '%H%M%S'))
t1=time.mktime( ta1)
t2=time.mktime( ta2)
print t1, t2

-2147483648.0 -2147483648.0

I just can not figure out, why the t1 and t2 are the same?
Thanks for your comments

Petr Jakes

Aug 30 '05 #1
4 10236
I don't get the same results:
import datetime, time
ta1=(time.strpt ime('000001', '%H%M%S'))
ta2=(time.strpt ime('230344', '%H%M%S'))
t1=time.mktime( ta1)
t2=time.mktime( ta2)
print t1, t2 -2208988799.0 -2208905776.0 print t1-t2

-83023.0

Suse 9.3, python 2.4 (all 64bit)
Matt

--

| Matt Hammond
| R&D Engineer, BBC Research and Development, Tadworth, Surrey, UK.
Aug 30 '05 #2
"McBooCzech " <pe**@tpc.cz> writes:
Hi, on Linux (Fedora FC4) and Python 2.4.1
I am trying to know the time delta in seconds between two times given
in the HHMMSS format. My code looks like:

import datetime, time
ta1=(time.strpt ime('000001', '%H%M%S'))
ta2=(time.strpt ime('230344', '%H%M%S'))
t1=time.mktime( ta1)
t2=time.mktime( ta2)
print t1, t2

-2147483648.0 -2147483648.0

I just can not figure out, why the t1 and t2 are the same?


Hm. You are trying to convert (1900, 1, 1, 0, 0, 1, 0, 1, -1) to epoch.
However, epochs start from 1970-01-01 00:00. So that at least is not right.

Hint... see what var ta1 is. With python2.3 you'll get overflow error, becuase
mktime argument is out of range.

--
# Edvard Majakari Software Engineer
# PGP PUBLIC KEY available Soli Deo Gloria!

$_ = '45647661726420 4d616a616b61726 92c206120436872 69737469616e20' ; print
join('',map{chr hex}(split/(\w{2})/)),uc substr(crypt(60 281449,'es'),2, 4),"\n";
Aug 30 '05 #3
according to the Python documentation:
http://docs.python.org/lib/module-time.html

===snip===
Values 100-1899 are always illegal.
..
..
strptime(string[, format])
..
..
The default values used to fill in any missing data are:
(1900, 1, 1, 0, 0, 0, 0, 1, -1)
===snip===

BTW, check the following code:
import datetime, time
print time.gmtime(tim e.mktime((1900, 1, 1, 0, 0, 0, 0, 1, -1)))

(1901, 12, 13, 20, 45, 52, 4, 347, 0)

but (1900, 1, 1, 0, 0, 0, 0, 1, -1) is (IMHO) expected.... Hmmm. But I
am just a newbie!!! :)

Anyway, maybe I am just using a wrong way how to calculate time delta
between two time values given in the format "HHMMSS".

Does Python provide some other ways how to calculate it?

Petr Jakes

Aug 30 '05 #4
"McBooCzech " <pe**@tpc.cz> writes:

===snip===
Values 100-1899 are always illegal.
.
.
strptime(string[, format])
.
.
The default values used to fill in any missing data are:
(1900, 1, 1, 0, 0, 0, 0, 1, -1)
===snip===

BTW, check the following code:
import datetime, time
print time.gmtime(tim e.mktime((1900, 1, 1, 0, 0, 0, 0, 1, -1))) (1901, 12, 13, 20, 45, 52, 4, 347, 0)

but (1900, 1, 1, 0, 0, 0, 0, 1, -1) is (IMHO) expected.... Hmmm. But I
am just a newbie!!! :)


You are comparing apples and oranges here. You checked documentation of
strptime, and the problem is in the use of time.mktime().

The point: time.mktime() returns Epoch time (seconds since 1970) and you are
passing it a tuple which is (way before) 1970. There is no such thing as
negative epoch. It is like computing packaging day of milk which hasn't been
milked from the cow yet :)

I really wonder what version of Python you are running:
import datetime, time
print time.gmtime(tim e.mktime((1900, 1, 1, 0, 0, 0, 0, 1, -1)))

Traceback (most recent call last):
File "<stdin>", line 1, in ?
OverflowError: mktime argument out of range

Python 2.3 and 2.4 both give the same error. As for the python version 2.2, no
datetime module was implemented.

--
# Edvard Majakari Software Engineer
# PGP PUBLIC KEY available Soli Deo Gloria!

$_ = '45647661726420 4d616a616b61726 92c206120436872 69737469616e20' ; print
join('',map{chr hex}(split/(\w{2})/)),uc substr(crypt(60 281449,'es'),2, 4),"\n";
Sep 5 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
2502
by: Bengt Richter | last post by:
Python 2.3.2 (#49, Oct 2 2003, 20:02:00) on win32 Type "help", "copyright", "credits" or "license" for more information. >>> import time >>> time.mktime((1969, 12, 31, 17, 0, 0, 0, 0, 0)) 3600.0 >>> time.mktime((1969, 12, 31, 17, 0, 0, 0, 0, 1)) 0.0 >>> time.mktime((1969, 12, 31, 16, 0, 0, 0, 0, 1))
5
1855
by: Dave | last post by:
I am working with a proprietary database that records the date, time, location, and speed of a vehicle. It is pulling this information from GPS unit tied to a vehicle. The table is populated with values that are pulled from the GPS unit every 30 seconds. I need to find the duration of time for when a vehicle is stopped. I have created a cursor that runs though all of the tables, and gathers the data for when the vehicle's speed is equal to...
5
2121
by: Paul | last post by:
Hi All, I know this is probably simple, but I'll ask anyway. I have a form which when submitted to the database the field in the database automatically adds date and time which is fine. My only problem is that my site is for the GMT UK time zone, but the database resides on a American server, IE the database records the local American time (-5 hours difference) and not the time of the users using it in the UK. Is there anyway to round...
5
3324
by: Carmine Cairo | last post by:
Hi, I'm working on a project and today I've note a little problem during the compile fase. Here a little piece of code: // 1st version welldone = 0; size = p->getSize(); backbone = new rightType;
3
1172
by: jv | last post by:
I have a timesheet data entry form with TimeIn and TimeOut textbox controls. I want the users to only view/enter/update the time in military-time format. The format of both controls are set to Short Time(hh:nn). The input mask for both are set 99:00;0;_ This works fine most of the time. The exception is when I click on a control that has a certain values (i.e. 12:02, 12:06, 12:14, 12:22, 12:23 ... 17:17). When I click on a control...
17
2196
by: Razzel | last post by:
I created this as a test: #include <time.h> main(){ printf(X1: %s\n", putim()); printf(X2: %s\n", putim()); } putim() { time_t t; time(&t); return(ctime(&t));
15
2006
by: Cesar Ronchese | last post by:
Hi, I built the sample code showing the problem with dates when viewed at different machines, different Time Zones and transported via Remoting. The zip can be downloaded here: www.carsoftnet.com.br/temp/sample_error_date.zip
2
1439
by: Ishan Bhalla | last post by:
Hello everyone, Is there any framework or API function i can use to get the date and time of any city in the world? Basically our server is based in Sydney and we need to know time in Perth when any scanning information comes from there. The server time is always Sydney time. Thanks in advance
3
1276
by: Joe | last post by:
Hi, I am facing a session Timeout problem on an ASP.NET project. The .NET project is deployed on a Windows server 2003 machine. Users connect to this machine to access the application. From time to time, users are disconnected(unspecified period of time but less than the maximum timeout problem which in our case is 60 minutes) from the program due to a session Timeout problem.I have made some tests on the machine and noticed that the...
0
8432
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
8343
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
8856
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
8762
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
8545
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
8633
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
5653
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
4347
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
1747
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.