Tokyo Time


8 points



This app figures out and displays the date and time in New Jersey and in Tokyo, Japan. We'll use the Date class, which we used for an earlier program. Tokyo is 14 hours ahead of New Jersey, so for example if it's 9 a.m. in New Jersey, it's 11 p.m. (23:00 in military time) in Tokyo. If it's 11 p.m. in New Jersey, it's 1 p.m. (13:00 in military time) - the following day - in Tokyo. This program uses military time.

Recall that the Date class has these GET methods that can be useful:

Here's an example:
var nowNJ = new Date();
var date = nowNJ.getDate();

The Date class also has these SET methods that you can use to change the date:

Here's an example:
This code would set the date's month to February.

In the app, when you click the button, the app figures out and displays the current time in both New Jersey and Tokyo.


Extra Credit (3 points)

If it's 3 minutes after 2 a.m., this time could be display as 2:3. If you write the extra-credit, this time would display as 02:03. If either the hour or minute or both is a single digit, a "0" is displayed before the single digit. You could write a function to do this. The function could accept a Date object as a parameter. IF statements could be used to add a "0" when needed. Finally, the function could return a string with the time. The basic form of the function could be:
function formatTime(date)
   return msg;

The code could send the New Jersey Date object into the function, and then send the Tokyo Date object in.



The video shows what a completed app should do. The video includes the extra-credit option.