How do i go by using the time function in python.... example
in php it would be
How can i do this in python?Code:$time = time ( ) - 60;
How do i go by using the time function in python.... example
in php it would be
How can i do this in python?Code:$time = time ( ) - 60;
Pretty much the same
Code:import time myTime = time.time() - 60
i like using strftime so that i can format the time however i like
%d = day
&m = month
%y = year eg 05
%Y = year eg 2005
%H = hour
%M = min
%S = sec
18052005183045Code:from time import strftime myTime = strftime('%d%m%Y%H%M%S')
or
18/05/05_18:30:45Code:myTime = strftime('%d/%m/%y_%H:%M:%S')
According to the documentation both functions return the time since the epoch (01/01/1979). The only difference I can see is that PHP returns an int value where Python returns a float.Originally Posted by xlordt
This can be changed by using the int() function to type-cast the float to an int.
Hope this helps X,Code:>>> import time >>> time.time() - 60 1116439289.4688611 >>> int(time.time() - 60) 1116439301 >>>
Mark.
hmm kool i guess i should recheck my codes.. and see whats up.. if not then i will just post the codes here and see what happends... thanx all
To be more exact, Python's epoch starts at 01/01/1970 at 0 Universal Time, which is midnight in Greenwich, England.
The correct use of strftime() would be:
Code:import time myTime = time.strftime('%m/%d/%y %H:%M:%S', time.localtime()) print myTime
I stand corrected, don't know where 1979 came from then. Thanks for the info Dietrich.
Mark.