A frequent source of annyance is the variety of times and dates used in different software packages. As I have been writing a lot of bash scripts lately (Aug2014) that parse strings, and I need to make some code timing studies, I have decided to assemble this little doc that covers a number of scripts and codes that deal with these issues.
The easiest place to start is the unix utility called date. I have used it on a variety of machines, and as long as I use the "-u" flag, I get a fairly uniform set of date/time strings for the current Universal Time. Below I cover examples of date, and a script that will write this date string to a user-named file.
% date Thu Aug 28 10:46:51 CDT 2014 % date -u Thu Aug 28 15:49:14 UTC 2014 % dspit CNAME start CNAME start Thu Aug 28 18:18:21 UTC 2014 # A hadcopy file with the UT time is made using arg1,arg2. % ls % ls S/ tstamp.CNAME_start % cat tstamp.CNAME_start Thu Aug 28 15:49:14 UTC 2014
The point of dspit is that I can run this script in different parts of another script or program and use it to establish a time stamp file. I may use these time stamp files in various ways. For instance, in the example above, I may be wanting a test for the code called "c14". I use the dspit script to create a file that creates a time stamp for when the c14 code was started. Note that the command line arguments for dspit (arg1,arg2) can be any strings I wish. I may use create a file later on (called tstamp.cl4_end) that marks the time that c14 finished processing. By using time difference script (see below) I can later determine how long c14 took to run in some useful units (i.e. seconds).
Here we use the dspit script to make a time stamp file. Then we access that file, split the time string into it's consituent parts, and finally compute the total time (from the sexigecimal time string) in units of seconds.
% dspit C01 start C01 start Wed Oct 4 02:41:19 UTC 2017 % ls tstamp.C01_start % cat tstamp.C01_start Wed Oct 4 02:41:19 UTC 2017 % dsep tstamp.C01_start 9679 % cat dsep.out Time String = 02:41:19 Time System = UTC Day Name = Wed Integer Day = 4 Month Name = Oct Year = 2017 Time in seconds (from tsp) = 9679In the example above, the dsep script is really just a demo script. It separates the parts you may need and then prints out the answers. The really practical script ( named "tsp") is what take one of those parts (the sexigecimal time) and write to standard out the TOTAL TIME IN SECONDS (in this case 9679 seconds) since the start of the UT day.
Now we use the script called tsdif (Time Stamp DIFference) to compute the time in seconds between two time stamp files. Just as we made "tstamp.Cname_Start" above, we can make the file "tstamp.Cname_End" at some later time. We compute the time difference in seconds with the simple command:
% ls tstamp.C01_end tstamp.C01_start % tsdif tstamp.C01_end tstamp.C01_start 396Our answer (396 seconds) comes to standard out. This routine is usually used to measure run times in scripts. I only gives times to the nearest second, and it does not handle date rollovers, but is usually easy to code and handy.