473,385 Members | 2,013 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

How to calculate two time?

I have two string like "2007-03-27T08:54:43+08:00 "
how do I get the hours between these two time(string format)?
Oct 8 '08 #1
6 1334

lookonI have two string like "2007-03-27T08:54:43+08:00 " how do I get
lookonthe hours between these two time(string format)?

Look in PyPI for dateutil, then:
>>import dateutil.parser
t1 = dateutil.parser.parse("2007-03-27T08:54:43+08:00")
t1
datetime.datetime(2007, 3, 27, 8, 54, 43, tzinfo=tzoffset(None, 28800))
>>t2 = dateutil.parser.parse("2007-03-29T10:00:00+02:00") >>t2
datetime.datetime(2007, 3, 29, 10, 0, tzinfo=tzoffset(None, 7200))
>>t2 - t1
datetime.timedelta(2, 25517)

Skip
Oct 8 '08 #2
Thank you for your help.It works.

However, I am using Google App Engine and cannot import dateutil and
epsilon.

Are there any other ways?
On Oct 8, 10:06*pm, s...@pobox.com wrote:
* * lookonI have two string like "2007-03-27T08:54:43+08:00 " how do I get
* * lookonthe hours between these two time(string format)?

Look in PyPI for dateutil, then:

* * >>import dateutil.parser
* * >>t1 = dateutil.parser.parse("2007-03-27T08:54:43+08:00")
* * >>t1
* * datetime.datetime(2007, 3, 27, 8, 54, 43, tzinfo=tzoffset(None,28800))
* * >>t2 = dateutil.parser.parse("2007-03-29T10:00:00+02:00") >>>t2
* * datetime.datetime(2007, 3, 29, 10, 0, tzinfo=tzoffset(None, 7200))
* * >>t2 - t1
* * datetime.timedelta(2, 25517)

Skip
Oct 9 '08 #3

lookonThank you for your help.It works. However, I am using Google
lookonApp Engine and cannot import dateutil and epsilon.

I don't know how Google App Engine works, but are you not able to install
pure Python modules?

lookonAre there any other ways?

Take a look at the time.strptime function to generate a tuple, then use

t = time.strptime(timestamp, format)
t1 = datetime.datetime(*t[0:6])

Note that with this solution you will have to handle the timezone offset
yourself.

Skip
Oct 9 '08 #4
but can you tell me what format is it?

in the str there is a float and I can not deal with it
On Oct 9, 7:20*pm, s...@pobox.com wrote:
* * lookonThank you for your help.It works. *However, I am using Google
* * lookonApp Engine and cannot import dateutil and epsilon.

I don't know how Google App Engine works, but are you not able to install
pure Python modules?

* * lookonAre there any other ways?

Take a look at the time.strptime function to generate a tuple, then use

* * t = time.strptime(timestamp, format)
* * t1 = datetime.datetime(*t[0:6])

Note that with this solution you will have to handle the timezone offset
yourself.

Skip
Oct 9 '08 #5
I have solved the problem. thank you

On Oct 9, 7:20*pm, s...@pobox.com wrote:
* * lookonThank you for your help.It works. *However, I am using Google
* * lookonApp Engine and cannot import dateutil and epsilon.

I don't know how Google App Engine works, but are you not able to install
pure Python modules?

* * lookonAre there any other ways?

Take a look at the time.strptime function to generate a tuple, then use

* * t = time.strptime(timestamp, format)
* * t1 = datetime.datetime(*t[0:6])

Note that with this solution you will have to handle the timezone offset
yourself.

Skip
Oct 9 '08 #6

lookonbut can you tell me what format is it?

Read the strftime man page on your computer or Google for strftime or read
the Python docs about the time.strftime function. (strftime and strptime
strive to have the same set of format characters.)

Skip
Oct 9 '08 #7

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

Similar topics

1
by: sg_s123 | last post by:
============================================================================ 02-Feb-04 03-Feb-04 Staff Staff 0800hr- 1300hr- 1700hr- 1900hr- 0800hr- 1300hr- 1700hr- 1900hr- Number...
7
by: Tim Quon | last post by:
Hi Is there any function to get the current time so I can calculate the execution time of my code? What all is in the time.h and sys/times.h? Thanks Tim
6
by: Herrcho | last post by:
in K&R Chapter 6.3 it mentions two methods to calculate NKEYS. and points out the first one which is to terminate the list of initializers with a null pointer, then loop along keytab until the...
4
by: Qwert | last post by:
Hello, I do: Debug.WriteLine("A: " & DateTime.Now.Ticks.ToString) REM Calculate a bunch of stuff. Some loops and math functions. Debug.WriteLine("B: " & DateTime.Now.Ticks.ToString) but...
1
by: Bujji | last post by:
Hi, How to calculate Heap memory used by a process in HPUX machine (Itanium) using aCC compiler at run time ( My ultimate aim is to calculate heap memory at run-time and write it into a log...
5
by: Michael | last post by:
Hi. I need dinamically calculate input text field based on parent static TD before showing content of input. Please, advice. Michael
5
by: Beemer Biker | last post by:
I cant seem to get that date into any DateTime to make my calculation directly by subtracting "01-01-0000" from "now". After reading this:...
2
by: Lancelot | last post by:
Hello everyone. This is my first post here, but I've been looking for answer many time. I have a crazy idea in my head and since I am quite a newby to python, I am not sure where to start or if...
9
by: brendanmcdonagh | last post by:
Hi, I am designing a project for my friend as I am just a week old baby to vb and want to implement what I've learnt so far. She wants to be able to put start time, end time and lunch for each...
6
by: rrstudio2 | last post by:
I am using the following vba code to calculate the median of a table in MS Access: Public Function MedianOfRst(RstName As String, fldName As String) As Double 'This function will calculate the...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
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...
0
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,...

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.