Computers store the current time in terms of the number of "ticks" that have elapsed since a certain date, known as the beginning of the "epoch." A tick is a metaphor for the ticking sound made by an analogue clock every second, however, the length of a tick varies for each operating system. Unix systems have a one-second tick, while Windows systems use a 100-nanosecond tick and Mac OS X systems have a one-millisecond tick. Similarly, different systems use different dates to mark the beginning of their epoch. For Windows, that date is Jan. 1, 1601, at precisely midnight UT/GMT. For Unix and Mac OS X, the epoch begins on Jan. 1, 1970, at precisely midnight UT/GMT. You can write a simple program in the free language Ruby that will take a number of ticks and compute the current date from them.
- Skill level:
- Moderately Easy
Things you need
Open a text editor and save the document with the name "tick2time.rb."
Paste the following code within it:
ticks = Integer(ARGV)
if ARGV == "--s":
# do nothing
elsif ARGV == "--ms":
ticks = ticks / 1000
elsif ARGV == "--ns":
ticks = ticks / 1000000
The first line is only for users of Mac OS X or Linux: it should identify the location where Ruby is installed. The program takes the number of ticks from the command line along with a "tick length" argument that can be set to "--s" for second, "--ms" for millisecond or "--ns" for nanosecond. Whatever the tick length is, it is adjusted to the second-length tick that Ruby expects for its Time function.
Save your work.
Tips and warnings
- The epoch is the epoch for the current operating system. So, "tick2time.rb --s 0" will give different results on Windows and Unix computers, since each computer begins its epoch at drastically different times.
- 20 of the funniest online reviews ever
- 14 Biggest lies people tell in online dating sites
- Hilarious things Google thinks you're trying to search for