Hi
I am new to Python.
I have v1.4.5 installed on my handset and I wish to do some data/time calculations.
Is there an obhect I can use to store a data/time and add or substract a number of days to/from it?
REgards
Patrick
Hi
I am new to Python.
I have v1.4.5 installed on my handset and I wish to do some data/time calculations.
Is there an obhect I can use to store a data/time and add or substract a number of days to/from it?
REgards
Patrick
Hi,
Well, you should check out the time module. It has all sorts of functions that can help. The documentation is here.
If you're willing to use PyS60 1.9.5 or later you can also use the datetime module.
Hi
TYhanks for your reply. What if I was to do the following, would I get todays date + 10 days?
time.gettime() + 10
How about having a tine representing 25/12/2009, would the following work?
time.mktime(time.struct_time(tm_year=2009, tm_mon=12, tm_mday=25, tm_hour=0, tm_min=0, tm_sec=0, tm_isdst=-1))
Regards
Patrick
There is no gettime function in the time module. You could do something like this:
time.time() returns the current time in seconds since January 1st, 1970. So you just add 10 times the number of seconds in a day.Code:time.time() + 10*86400
Have you tried it? It's always better to try something and see for yourself if it worksIf it doesn't, post your problem here and we'll try to help.
I have tried constructing a struct_time "object" called base in the following way.
base.tm_year = 2009
base.tm_mon = 3
base.tm_mday = 1
base.tm_hour = 0
base.tm_min = 0
base.tm_sec = 0
base.tm_isdst = -1
When I try to run this, the interpreter tells me that "base" is undefined. How do I tell the interpreter that "base" is a struct_time "object"?
struct_time the type of the tuples returned by functions like localtime(). Anyway, you can create s struct_time object from a sequence by calling the struct_time function on that sequence:
Code:example = [2009, 6, 25, 10, 30, 43, 3, 176, 1] base = time.struct_time(example)