*COBOL COBOL COBOL COBOL COBOL* You will write a program that will print out the
ID: 3772989 • Letter: #
Question
*COBOL COBOL COBOL COBOL COBOL*
You will write a program that will print out the GMT equivalent for the current time. For example, for the time 1:48 PM and some seconds (08 seconds) EST on December 11, 2015, the result will be:
Current GMT 12/11/2015 18:48:08
Your program MUST include a provision for the GMT time being before or after the current time. Also note that the date may be different for the GMT time versus the current (local) time. The output of the program must be in exactly the format shown above.
A good strategy (and one I would like you to follow) is to convert the current time and date into the number of seconds since midnight 12/31/1600, determine the GMT shift in seconds (either positive or negative), and then convert the time in seconds since 12/31/2015 to normal GMT time as shown above.
If you turn in this program after midnight on December 18, it will not be graded.
Explanation / Answer
#include #include int main(void) { struct tm t; time_t t_of_day; t.tm_year = 2015-1600; t.tm_mon = 11; t.tm_mday = 3; t.tm_hour = 18; t.tm_min = 0; t.tm_sec = 0; t.tm_isdst = 0; t_of_day = mktime(&t); printf(ctime(&t_of_day)); return 0; } final String pubDate = "2015-12-31"; SimpleDateFormat f = new SimpleDateFormat("yyyy-MM-dd"); f.setTimeZone(TimeZone.getTimeZone("UTC")); Date d = f.parse(pubDate, new ParsePosition(0)); f = new SimpleDateFormat("E yyyy-MM-dd HH:mm"); f.setTimeZone(TimeZone.getTimeZone("UTC")); System.out.println(f.getTimeZone().getID() + " " + f.format(d)); f.setTimeZone(TimeZone.getTimeZone("America/Los_Angeles")); System.out.println(f.getTimeZone().getID() + " " + f.format(d)); f.setTimeZone(TimeZone.getTimeZone("Pacific/Honolulu")); System.out.println(f.getTimeZone().getID() + " " + f.format(d)); f.setTimeZone(TimeZone.getTimeZone("Pacific/Kiritimati")); System.out.println(f.getTimeZone().getID() + " " + f.format(d)); }Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.