473,795 Members | 3,063 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Time

I need to convert the string below into epoch seconds so that I can
perform substractions and additions. I assume I will need to break it
up into a time_t struct and use mktime. Two questions if you will
please:

Is there a way to use multiple separator characters for split similar
to awk's [|] style?

Could you point to an example of a python time_t struct?

05/11/2007 15:30

Thanks,

jvh

May 11 '07 #1
13 2096
>
Could you point to an example of a python time_t struct?
Or maybe that should be a tm struct???

May 11 '07 #2
Sorry, reading a little closer I see that the time tuple is apparently
an ordinary list.

jvh

May 11 '07 #3
On May 12, 7:46 am, HMS Surprise <j...@datavoice int.comwrote:

[first message]

HS ==I need to convert the string below into epoch seconds so that I
can
perform substractions and additions.

JM ==I presume you mean "seconds since the epoch". You don't need to
do that.

HS ==I assume I will need to break it
up into a time_t struct and use mktime.

JM ==You assume wrongly. The time module exists (IMVHO) solely as a
crutch for people who are converting C etc code that uses the time.h
functions from the C standard library. If you are starting off from
scratch, use the Python datetime module -- especially if you need to
store and manipulate pre-1970 dates; e.g. the date of birth of anyone
aged more than about 37.5 years :-)

HS ==Two questions if you will
please:

Is there a way to use multiple separator characters for split similar
to awk's [|] style?

JM ==Only if you can find such a way in the manual.

HS ==Could you point to an example of a python time_t struct?

JM ==Python doesn't have that; it's a C concept
HS ==05/11/2007 15:30

[second message]

HS== Could you point to an example of a python time_t struct?

Or maybe that should be a tm struct???

JM ==See previous answer.

[third message]

HS ==Sorry, reading a little closer I see that the time tuple is
apparently
an ordinary list.

JM ==Huh? A tuple is a tuple. A tuple is not a list, not even a very
extraordinary one.

If you are desperate to use the time module, try this:
>>import time
s = "05/11/2007 15:30"
fmt = "%m/%d/%Y %H:%M"
# Given the current date, I'm presuming that your example indicates
that you adhere to the "month-first-contrary-to-common-sense"
religion :-)
>>time.strptime (s, fmt)
(2007, 5, 11, 15, 30, 0, 4, 131, -1)

otherwise:
>>import datetime
d1 = datetime.dateti me.strptime(s, fmt)
d1
datetime.dateti me(2007, 5, 11, 15, 30)
>>d2 = datetime.dateti me(2007, 5, 1)
d2
datetime.dateti me(2007, 5, 1, 0, 0)
>>delta = d1 - d2
delta
datetime.timede lta(10, 55800)
>>days_diff = delta.days + delta.seconds / 60. / 60. / 24.
days_diff
10.645833333333 334

Do read the datetime module documentation for more info ... in
particular the timedelta object has a microseconds attribute; in
general there is a whole heap of functionality in there.

HTH,
John

May 11 '07 #4
Thanks for posting. I sure am sorry that I wasted your time. I should
have started the post stating I am using jython 2.2.3 and apparently
it has no datetime module. But I will keep datetime in mind for future
reference.

Since I had no datetime I cobbled out the following. Seems to work
thus far. Posted here for the general amusement of the list.

Regards,

jvh

~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~

from time import *
s = '05/11/2007 1:23 PM'
t = s.split()
mdy = t[0].split('/')

hrMn = t[1].split(':')
if t[2] == 'PM':
hrMn[0] = int(hrMn[0]) + 12

tuple =(int(mdy[2]), int(mdy[0]), int(mdy[1]), hrMn[0], int(hrMn[1]),
0,0,0,0)
print tuple

eTime = mktime(tuple)
print 'eTime', eTime

May 14 '07 #5
On May 14, 9:00 am, HMS Surprise <j...@datavoice int.comwrote:
Thanks for posting. I sure am sorry that I wasted your time. I should
have started the post stating I am using jython 2.2.3 and apparently
it has no datetime module. But I will keep datetime in mind for future
reference.

Since I had no datetime I cobbled out the following. Seems to work
thus far. Posted here for the general amusement of the list.

Regards,

jvh

~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~

from time import *
s = '05/11/2007 1:23 PM'
t = s.split()
mdy = t[0].split('/')

hrMn = t[1].split(':')
if t[2] == 'PM':
hrMn[0] = int(hrMn[0]) + 12

tuple =(int(mdy[2]), int(mdy[0]), int(mdy[1]), hrMn[0], int(hrMn[1]),
0,0,0,0)
print tuple

eTime = mktime(tuple)
print 'eTime', eTime
Since jython works with Java, why not use Java's time/datetime
modules? Various links abound. Here are a few:

http://www.raditha.com/blog/archives/000552.html
http://www.xmission.com/~goodhill/dates/deltaDates.html
http://www.velocityreviews.com/forum...variables.html

Maybe those will give you some hints.

Mike

May 14 '07 #6
if t[2] == 'PM':
hrMn[0] = int(hrMn[0]) + 12

Oops, should be:
hrMn[0] = int(hrMn[0]
if t[2] == 'PM':
hrMn[0] += 12
May 14 '07 #7
On May 14, 9:09 am, kyoso...@gmail. com wrote:
On May 14, 9:00 am, HMS Surprise <j...@datavoice int.comwrote:
Thanks for posting. I sure am sorry that I wasted your time. I should
have started the post stating I am using jython 2.2.3 and apparently
it has no datetime module. But I will keep datetime in mind for future
reference.
Since I had no datetime I cobbled out the following. Seems to work
thus far. Posted here for the general amusement of the list.
Regards,
jvh
~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~
from time import *
s = '05/11/2007 1:23 PM'
t = s.split()
mdy = t[0].split('/')
hrMn = t[1].split(':')
if t[2] == 'PM':
hrMn[0] = int(hrMn[0]) + 12
tuple =(int(mdy[2]), int(mdy[0]), int(mdy[1]), hrMn[0], int(hrMn[1]),
0,0,0,0)
print tuple
eTime = mktime(tuple)
print 'eTime', eTime

Since jython works with Java, why not use Java's time/datetime
modules? Various links abound. Here are a few:

http://www.raditha.com/blog/archives...erence-in-date...

Maybe those will give you some hints.

Mike
Excellent idea.

Thanks Mike.
jvh

May 14 '07 #8
On May 14, 9:22 am, HMS Surprise <j...@datavoice int.comwrote:
if t[2] == 'PM':
hrMn[0] = int(hrMn[0]) + 12

Oops, should be:
hrMn[0] = int(hrMn[0]
if t[2] == 'PM':
hrMn[0] += 12
Oops +=1, should be:
hrMn[0] = int(hrMn[0]
if t[2] == 'PM':
hrMn[0] += 12

Need more starter fluid, coffee please!!!

May 14 '07 #9
En Mon, 14 May 2007 11:27:35 -0300, HMS Surprise <jo**@datavoice int.com>
escribió:
On May 14, 9:22 am, HMS Surprise <j...@datavoice int.comwrote:

Oops +=1, should be:
hrMn[0] = int(hrMn[0]
if t[2] == 'PM':
hrMn[0] += 12

Need more starter fluid, coffee please!!!
Still won't work for 12 AM nor 12 PM...

--
Gabriel Genellina

May 14 '07 #10

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

Similar topics

8
2964
by: Bart Nessux | last post by:
am I doing this wrong: print (time.time() / 60) / 60 #time.time has been running for many hours if time.time() was (21600/60) then that would equal 360/60 which would be 6, but I'm not getting 6 so I'm not doing the division right, any tips?
5
3652
by: David Stockwell | last post by:
I'm sure this has been asked before, but I wasn't able to find it. First off I know u can't change a tuple but if I wanted to increment a time tuple by one day what is the standard method to do that? I've tried the obvious things and haven't gotten very far. I have a time tuple that was created like this: aDate = '19920228' x = time.strptime(aDate,"%Y%m%d")
6
12952
by: David Graham | last post by:
Hi I have asked this question in alt.php as the time() function as used in setcookie belongs to php - or does it belong equally in the javascript camp - bit confused about that. Anyway, can anyone here put me straight on the following: I had a look at the time() function came across this: "To clarify, it seems this function returns the time of the computer's clock and does not do any timezone adjustments to return GMT, so you are...
3
3158
by: Szabolcs Nagy | last post by:
I have to measure the time of a while loop, but with time.clock i always get 0.0s, although python manual sais: "this is the function to use for benchmarking Python or timing algorithms" So i tested timer functions capabilities with a short script: import time import os
6
2854
by: Rebecca Smith | last post by:
Today’s question involves two time text boxes each set to a different time zone. Initially txtCurrentTime will be set to Pacific Time or system time. This will change with system time as we travel across the country. txtRaceTime will always be set to Central Time regardless of where we are in the US. At first I tried ‘Now() – “xx:xx:xx” but that produced an error. Anyway as we approach the east coast the ‘minus’ would need to be a...
3
2723
by: luscus | last post by:
Thanks for all the responses on my first question. Unfortunately the answers I was given were too complicated for my small brain , and neophite condition to understand. So if you could talk down to me and write in easier terms I would be very gratefull to all you access wizards! Here is my problem. I have a table with maybe 10 fields, It is used to imput information taken over the phone to solve patient problems in our Spanish...
3
2033
by: cj | last post by:
If I want to check to see if it's after "11:36 pm" what would I write? I'm sure it's easy but I'm getting tired of having to work with dates and times. Sometimes I just want time or date. And to be able to do comparisons on them.
1
14602
by: davelist | last post by:
I'm guessing there is an easy way to do this but I keep going around in circles in the documentation. I have a time stamp that looks like this (corresponding to UTC time): start_time = '2007-03-13T15:00:00Z' I want to convert it to my local time. start_time = time.mktime(time.strptime(start_time, '%Y-%m-%dT%H:%M:
2
19587
by: Roseanne | last post by:
We are experiencing very slow response time in our web app. We run IIS 6 - windows 2003. I ran iisstate. Here's what I got. Any ideas?? Opened log file 'F:\iisstate\output\IISState-812.log' *********************** Starting new log output
9
8301
by: Ron Adam | last post by:
I'm having some cross platform issues with timing loops. It seems time.time is better for some computers/platforms and time.clock others, but it's not always clear which, so I came up with the following to try to determine which. import time # Determine if time.time is better than time.clock # The one with better resolution should be lower.
0
9519
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
10436
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
10213
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
10163
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
9040
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
7538
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
5563
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4113
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
2
3722
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.