How to get Time difference from system time?

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • idealfellow
    New Member
    • Jan 2008
    • 21

    How to get Time difference from system time?

    I am using the following to get the time:

    puts Time.now --> starting of my script

    <MY CODE>

    puts Time.now --> end of my script

    I want to get the Time difference between two Time.now
    Problem I am facing is i cannot directly take the difference as Time.now displays the time in following format : "Tue Feb 12 19:55:37 +0530 2008"
    Any other better way to solve it?

    Cheers
  • improvcornartist
    Recognized Expert Contributor
    • May 2007
    • 303

    #2
    You can subtract the times to get the number of seconds between. Then you will have to do some manipulation to get an output in a format you want. For instance, to determine the number of minutes and seconds a piece of code runs, you could use[CODE=ruby]@start = Time.now
    #Execute code
    @run_time = Time.now - @start
    p sprintf("%d min ", @run_time / 60) + sprintf("%0.2f sec", @run_time % 60)[/CODE]

    Comment

    • idealfellow
      New Member
      • Jan 2008
      • 21

      #3
      Originally posted by improvcornartis t
      You can subtract the times to get the number of seconds between. Then you will have to do some manipulation to get an output in a format you want. For instance, to determine the number of minutes and seconds a piece of code runs, you could use[CODE=ruby]@start = Time.now
      #Execute code
      @run_time = Time.now - @start
      p sprintf("%d min ", @run_time / 60) + sprintf("%0.2f sec", @run_time % 60)[/CODE]
      Thanks Alot, works Fine :)

      Comment

      Working...