Thread: time function

    #1
  1. Only the strong survives!!.
    Devshed God 1st Plane (5500 - 5999 posts)

    Join Date
    Feb 2003
    Location
    A World of wonders.
    Posts
    5,583
    Rep Power
    407

    time function


    How do i go by using the time function in python.... example
    in php it would be
    Code:
    $time = time ( ) - 60;
    How can i do this in python?
  2. #2
  3. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Oct 2004
    Location
    Colorado, USA
    Posts
    68
    Rep Power
    10
    Pretty much the same

    Code:
    import time
    
    myTime = time.time() - 60
  4. #3
  5. Only the strong survives!!.
    Devshed God 1st Plane (5500 - 5999 posts)

    Join Date
    Feb 2003
    Location
    A World of wonders.
    Posts
    5,583
    Rep Power
    407
    Originally Posted by djjhouse
    Pretty much the same

    Code:
    import time
    
    myTime = time.time() - 60
    hmm i though so.. but its not working for me.. but will tripple try it when i get home
  6. #4
  7. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Nov 2004
    Posts
    40
    Rep Power
    10
    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

    Code:
    from time import strftime
        myTime = strftime('%d%m%Y%H%M%S')
    18052005183045
    or
    Code:
     myTime = strftime('%d/%m/%y_%H:%M:%S')
    18/05/05_18:30:45
  8. #5
  9. Hello World :)
    Devshed Frequenter (2500 - 2999 posts)

    Join Date
    Mar 2003
    Location
    Hull, UK
    Posts
    2,537
    Rep Power
    69
    Originally Posted by xlordt
    hmm i though so.. but its not working for me.. but will tripple try it when i get home
    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.

    This can be changed by using the int() function to type-cast the float to an int .

    Code:
    >>> import time
    >>> time.time() - 60
    1116439289.4688611
    >>> int(time.time() - 60)
    1116439301
    >>>
    Hope this helps X,

    Mark.

    Comments on this post

    • djjhouse agrees : That is probably exactly it. Cleans it up a bit.
    programming language development: www.netytan.com Hula

  10. #6
  11. Only the strong survives!!.
    Devshed God 1st Plane (5500 - 5999 posts)

    Join Date
    Feb 2003
    Location
    A World of wonders.
    Posts
    5,583
    Rep Power
    407
    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
  12. #7
  13. Contributing User
    Devshed Novice (500 - 999 posts)

    Join Date
    Feb 2005
    Posts
    611
    Rep Power
    65

    Smile


    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
  14. #8
  15. Hello World :)
    Devshed Frequenter (2500 - 2999 posts)

    Join Date
    Mar 2003
    Location
    Hull, UK
    Posts
    2,537
    Rep Power
    69

    :)


    I stand corrected, don't know where 1979 came from then . Thanks for the info Dietrich.

    Mark.
    programming language development: www.netytan.com Hula


IMN logo majestic logo threadwatch logo seochat tools logo