Prior to the late nineteenth century, time keeping was a purely localphenomenon. Each town would set their clocks to noon when the sun reachedits zenith each day. A clockmaker or town clock would be the "official"time and the citizens would set their pocket watches and clocks to thetime of the town - enterprising citizens would offer their services asmobile clock setters, carrying a watch with the accurate time to adjustthe clocks in customer's homes on a weekly basis. Travel between citiesmeant having to change one's pocket watch upon arrival.
However, once railroads began to operate and move people rapidly acrossgreat distances, time became much more critical. In the early yearsof the railroads, the schedules were very confusing because each stopwas based on a different local time. The standardization of time wasessential to efficient operation of railroads.
In 1878, Canadian Sir Sanford Fleming proposed the system of worldwidetime zones that we use today. He recommended that the world be dividedinto twenty-four time zones, each spaced 15 degrees of longitudeapart. Since the earth rotates once every 24 hours and there are 360degrees of longitude, each hour the earth rotates one-twenty-fourth ofa circle or 15� of longitude. Sir Fleming's time zones were heralded asa brilliant solution to a chaotic problem worldwide.
United States railroad companies began utilizing Fleming's standard timezones on November 18, 1883. In 1884 an International Prime MeridianConference was held in Washington D.C. to standardize time and selectthe Prime Meridian. The conference selected the longitude of Greenwich,England as zero degrees longitude and established the 24 time zones basedon the Prime Meridian. Although the time zones had been established,not all countries switched immediately. Though most U.S. states beganto adhere to the Pacific, Mountain, Central, and Eastern time zones by1895, Congress didn't make the use of these time zones mandatory untilthe Standard Time Act of 1918.
Today, many countries operate on variations of the time zones proposedby Sir Fleming. All of China (which should span five time zones) uses asingle time zone - eight hours ahead of Coordinated Universal Time (knownby the abbreviation UTC - based on the time zone running through Greenwichat 0� longitude). Russia adheres to its designated time zones although theentire country is on permanent Daylight Saving Time and is an hour aheadof their actual zones. Australia uses three time zones - its central timezone is a half-hour ahead of its designated time zone. Several countriesin the Middle East and South Asia also utilize half-hour time zones.
Since time zones are based on segments of longitude and lines of longitudenarrow at the poles, scientists working at the North and South Polessimply use UTC time. Otherwise, Antarctica would be divided into 24 verythin time zones!
Time zones have recently been given standard capital-letter abbreviations as follows:
UTC Coordinated Universal Time GMT Greenwich Mean Time, defined as UTC BST British Summer Time, defined as UTC+1 hour IST Irish Summer Time, defined as UTC+1 hour WET Western Europe Time, defined as UTC WEST Western Europe Summer Time, defined as UTC+1 hour CET Central Europe Time, defined as UTC+1 CEST Central Europe Summer Time, defined as UTC+2 EET Eastern Europe Time, defined as UTC+2 EEST Eastern Europe Summer Time, defined as UTC+3 MSK Moscow Time, defined as UTC+3 MSD Moscow Summer Time, defined as UTC+4 AST Atlantic Standard Time, defined as UTC-4 hours ADT Atlantic Daylight Time, defined as UTC-3 hours NST Newfoundland Standard Time, defined as UTC-3.5 hours NDT Newfoundland Daylight Time, defined as UTC-2.5 hours EST Eastern Standard Time, defined as UTC-5 hours EDT Eastern Daylight Saving Time, defined as UTC-4 hours CST Central Standard Time, defined as UTC-6 hours CDT Central Daylight Saving Time, defined as UTC-5 hours MST Mountain Standard Time, defined as UTC-7 hours MDT Mountain Daylight Saving Time, defined as UTC-6 hours PST Pacific Standard Time, defined as UTC-8 hours PDT Pacific Daylight Saving Time, defined as UTC-7 hours HST Hawaiian Standard Time, defined as UTC-10 hours AKST Alaska Standard Time, defined as UTC-9 hours AKDT Alaska Standard Daylight Saving Time, defined as UTC-8 hours AEST Australian Eastern Standard Time, defined as UTC+10 hours AEDT Australian Eastern Daylight Time, defined as UTC+11 hours ACST Australian Central Standard Time, defined as UTC+9.5 hours ACDT Australian Central Daylight Time, defined as UTC+10.5 hours AWST Australian Western Standard Time, defined as UTC+8 hoursGiven the current time in one time zone, you are to compute what time it is in anothertime zone. The first line of input contains N, the number of test cases.For each case a line is given with a time, and 2 time zone abbreviations. Time is given in standard a.m./p.m. format with midnight denoted "midnight" and noon denoted "noon" (12:00 a.m. and 12:00 p.m. are oxymorons).Assuming the given time is the current time in the first time zone, givethe current time in the second time zone.
4 noon HST CEST 11:29 a.m. EST GMT 6:01 p.m. CST UTC 12:40 p.m. ADT MSK
midnight 4:29 p.m. 12:01 a.m. 6:40 p.m.时区转换的问题
import java.io.FileInputStream; import java.io.BufferedInputStream; import java.io.OutputStreamWriter; import java.io.PrintWriter; import java.util.Scanner; import java.util.HashMap; public class Main implements Runnable { private static final boolean DEBUG = false; private PrintWriter cout; private Scanner cin; private HashMap<String, Double> hm; private String time, amOrpm; private String timezone1, timezone2; private int t; private void init() { try { if (DEBUG) { cin = new Scanner(new BufferedInputStream(new FileInputStream("d:\\OJ\\uva_in.txt"))); } else { cin = new Scanner(new BufferedInputStream(System.in)); } cout = new PrintWriter(new OutputStreamWriter(System.out)); initHashMap(); } catch (Exception e) { e.printStackTrace(); } } private void initHashMap() { hm = new HashMap<String, Double>(); hm.put("UTC", 0.0); hm.put("GMT", 0.0); hm.put("BST", 1.0); hm.put("IST", 1.0); hm.put("WET", 0.0); hm.put("WEST", 1.0); hm.put("CET", 1.0); hm.put("CEST", 2.0); hm.put("EET", 2.0); hm.put("EEST", 3.0); hm.put("MSK",3.0); hm.put("MSD", 4.0); hm.put("AST", -4.0); hm.put("ADT", -3.0); hm.put("NST", -3.5); hm.put("NDT", -2.5); hm.put("EST", -5.0); hm.put("EDT", -4.0); hm.put("CST", -6.0); hm.put("CDT", -5.0); hm.put("MST", -7.0); hm.put("MDT", -6.0); hm.put("PST", -8.0); hm.put("PDT", -7.0); hm.put("HST", -10.0); hm.put("AKST", -9.0); hm.put("AKDT", -8.0); hm.put("AEST", 10.0); hm.put("AEDT", 11.0); hm.put("ACST", 9.5); hm.put("ACDT", 10.5); hm.put("AWST", 8.0); } private void input() { time = cin.next(); if (time.compareTo("noon") == 0) { t = 12 * 60; timezone1 = cin.next(); timezone2 = cin.next(); } else if (time.compareTo("midnight") == 0) { t = 0; timezone1 = cin.next(); timezone2 = cin.next(); } else { amOrpm = cin.next(); timezone1 = cin.next(); timezone2 = cin.next(); if (amOrpm.compareTo("a.m.") == 0) { int index = time.indexOf(":"); int hour = Integer.parseInt(time.substring(0, index)); int min = Integer.parseInt(time.substring(index + 1)); if (hour == 12) { t = min; } else { t = hour * 60 + min; } } else { int index = time.indexOf(":"); int hour = Integer.parseInt(time.substring(0, index)); int min = Integer.parseInt(time.substring(index + 1)); if (hour != 12) { hour += 12; } t = hour * 60 + min; } } } private void solve() { double t1 = hm.get(timezone1); double t2 = hm.get(timezone2); double tmp = t2 - t1; if (tmp < 0) { tmp += 24; } int tmp1 = t + (int)(tmp * 60); if (tmp1 > 1440) tmp1 -= 1440; if (tmp1 % 1440 == 0) cout.println("midnight"); else if (tmp1 == 12 * 60) cout.println("noon"); else if (tmp1 < 60) cout.printf("12:%02d a.m.\n", tmp1); else if (tmp1 < 720) cout.printf("%d:%02d a.m.\n", tmp1 / 60 , tmp1 % 60); else if (tmp1 < 780) cout.printf("%d:%02d p.m.\n",tmp1 / 60 , tmp1 % 60); else cout.printf("%d:%02d p.m.\n", (tmp1 / 60 - 12), tmp1 % 60); cout.flush(); } public void run() { init(); int t = cin.nextInt(); while (t-- > 0) { input(); solve(); } } public static void main(String[] args) { new Thread(new Main()).start(); } }