Displaying the Current Time

Write a class named ShowTime that takes one argument, a string representing the timezone. The output should be the current time, updated every second, when run from the command line.

Sample run:

$ java ShowTime edt
 2:24:09 PM EDT   (Ctrl-C to exit)

One may find the following facts useful to this end:

  • The System.currentTimeMillis() method gives the time in milliseconds that has passed since 00:00:00, Jan 1, 1970

  • The Thread.sleep(n) method will pause a program's execution for $n$ milliseconds.

    Note, when one uses this method Eclipse complains that there is an "Unhandled exception type InterruptedException". Choosing the quick fix "Surround with try/catch" from the context menu will resolve this issue. Exactly what exceptions are and how one catches them will be discussed at a later date. For now, however, this will let one use the Thread.sleep(n) method.

  • One can print a backspace character "\b" followed by any printable character to change the last character previously printed to the console. You may print multiple backspace characters, if desired, to get to an earlier position in previously printed text. That said, you can not backspace past a line feed.

    Important: a program doing this must be run from the command line to work correctly. Eclipse has a 6+ year old bug that doesn't allow one to print backspace characters properly.

  • Typing "Ctrl-C" automatically halts any java program run from the command line.

  • The timezone might be entered with lowercase characters, uppercase characters, or a mixture of both. For simplicity sake, you may assume the timezone will be either "UTC" (the timezone used by System.currentTimeMillis()) or "EDT" (the timezone of Atlanta, GA which has a 4 hour offset from UTC).