473,396 Members | 1,785 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,396 software developers and data experts.

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
Feb 12 '08 #1
2 8888
improvcornartist
303 Expert 100+
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
Expand|Select|Wrap|Line Numbers
  1. @start = Time.now
  2. #Execute code
  3. @run_time = Time.now - @start
  4. p sprintf("%d min ", @run_time / 60) + sprintf("%0.2f sec", @run_time % 60)
Feb 12 '08 #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
Expand|Select|Wrap|Line Numbers
  1. @start = Time.now
  2. #Execute code
  3. @run_time = Time.now - @start
  4. p sprintf("%d min ", @run_time / 60) + sprintf("%0.2f sec", @run_time % 60)
Thanks Alot, works Fine :)
Feb 13 '08 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

17
by: newbiecpp | last post by:
I have hard time to understand run-time environment. Let assume that I have a program that has a simple variable alpha. When this variable is statically allocated, the compiler can use the...
3
by: Jon Davis | last post by:
The date string: "Thu, 17 Jul 2003 12:35:18 PST" The problem: // this fails on PST DateTime myDate = DateTime.Parse("Thu, 17 Jul 2003 12:35:18 PST"); Help? Jon
3
by: Reney | last post by:
I am using Access in my project. In one of the forms, I am calling two tables, and two of the columns have date/time type, namely "ClockIn" and "ClockOut". I created a dataset and filled the...
11
by: chopsnsauce | last post by:
Here's the example: Dim frm As New FORM1 Try frm.show Catch ex As Exception msgbox ex.message
3
by: Randall Parker | last post by:
Suppose one has a database of UTC times that are from different dates in the past. The problem with translating those times to a local time is that one does not know for each UTC time whether the...
3
by: moni | last post by:
This is all in C: I have 2 time values: System time and an input from the user. 1) System time is in the form of seconds from 1/1/1970 calculated by using time_t secs;
18
by: moni | last post by:
I have 2 time values: System time and an input from the user. 1) System time is in the form of seconds from 1/1/1970 calculated by using
1
by: indiarocks | last post by:
This is probably a very basic question, how do I find out the difference between two system time. I tried x1 = t1.clock x2 = t2.clock x2 - x1 doesn't seem to give me the difference. ...
3
by: bbawa1 | last post by:
Hi, I have a table which has a field ItemsReceived of type datetime. I have a grid view which has two columns. In first column i have to show the data from field ItemsReceived and in second...
19
by: xianwei | last post by:
#include <stdio.h> #include <stdlib.h> #include <time.h> int main ( int argc, char *argv ) { long i = 10000000L; clock_t start, end; double duration;
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: 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
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:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
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
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

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.