⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 timeutil.java

📁 mysql5.0 JDBC 驱动 放在glassfish或者tomcat的lib文件夹下就可以了
💻 JAVA
📖 第 1 页 / 共 4 页
字号:
		tempMap.put("OMSST", new String[] { "Asia/Omsk" });		tempMap.put("OMST", new String[] { "Asia/Omsk" });		tempMap.put("PDDT", new String[] { "America/Inuvik",				"America/Whitehorse", "America/Dawson" });		tempMap.put("PDT", new String[] { "America/Los_Angeles",				"America/Juneau", "America/Boise", "America/Vancouver",				"America/Dawson_Creek", "America/Inuvik", "America/Whitehorse",				"America/Dawson", "America/Tijuana" });		tempMap.put("PEST", new String[] { "America/Lima" });		tempMap.put("PET", new String[] { "America/Lima" });		tempMap.put("PETMT", new String[] { "Asia/Kamchatka" });		tempMap.put("PETST", new String[] { "Asia/Kamchatka" });		tempMap.put("PETT", new String[] { "Asia/Kamchatka" });		tempMap.put("PGT", new String[] { "Pacific/Port_Moresby" });		tempMap.put("PHOT", new String[] { "Pacific/Enderbury" });		tempMap.put("PHST", new String[] { "Asia/Manila" });		tempMap.put("PHT", new String[] { "Asia/Manila" });		tempMap.put("PKT", new String[] { "Asia/Karachi" });		tempMap.put("PMDT", new String[] { "America/Miquelon" });		tempMap.put("PMMT", new String[] { "Pacific/Port_Moresby" });		tempMap.put("PMST", new String[] { "America/Miquelon" });		tempMap.put("PMT", new String[] { "Antarctica/DumontDUrville",				"Europe/Prague", "Europe/Paris", "Europe/Monaco",				"Africa/Algiers", "Africa/Tunis", "America/Panama",				"America/Paramaribo" });		tempMap.put("PNT", new String[] { "Pacific/Pitcairn" });		tempMap.put("PONT", new String[] { "Pacific/Ponape" });		tempMap.put("PPMT", new String[] { "America/Port-au-Prince" });		tempMap.put("PST", new String[] { "Pacific/Pitcairn",				"America/Los_Angeles", "America/Juneau", "America/Boise",				"America/Vancouver", "America/Dawson_Creek", "America/Inuvik",				"America/Whitehorse", "America/Dawson", "America/Hermosillo",				"America/Mazatlan", "America/Tijuana" });		tempMap.put("PWT", new String[] { "Pacific/Palau",				"America/Los_Angeles", "America/Juneau", "America/Boise",				"America/Tijuana" });		tempMap.put("PYST", new String[] { "America/Asuncion" });		tempMap.put("PYT", new String[] { "America/Asuncion" });		tempMap.put("QMT", new String[] { "America/Guayaquil" });		tempMap.put("RET", new String[] { "Indian/Reunion" });		tempMap.put("RMT", new String[] { "Atlantic/Reykjavik", "Europe/Rome",				"Europe/Riga", "Asia/Rangoon" });		tempMap.put("S", new String[] { "Europe/Moscow" });		tempMap.put("SAMMT", new String[] { "Europe/Samara" });		tempMap				.put("SAMST",						new String[] { "Europe/Samara", "Asia/Samarkand" });		tempMap.put("SAMT", new String[] { "Europe/Samara", "Asia/Samarkand",				"Pacific/Pago_Pago", "Pacific/Apia" });		tempMap.put("SAST", new String[] { "Africa/Maseru", "Africa/Windhoek",				"Africa/Johannesburg", "Africa/Mbabane" });		tempMap.put("SBT", new String[] { "Pacific/Guadalcanal" });		tempMap.put("SCT", new String[] { "Indian/Mahe" });		tempMap.put("SDMT", new String[] { "America/Santo_Domingo" });		tempMap.put("SGT", new String[] { "Asia/Singapore" });		tempMap.put("SHEST", new String[] { "Asia/Aqtau" });		tempMap.put("SHET", new String[] { "Asia/Aqtau" });		tempMap.put("SJMT", new String[] { "America/Costa_Rica" });		tempMap.put("SLST", new String[] { "Africa/Freetown" });		tempMap.put("SMT", new String[] { "Atlantic/Stanley",				"Europe/Stockholm", "Europe/Simferopol", "Asia/Phnom_Penh",				"Asia/Vientiane", "Asia/Kuala_Lumpur", "Asia/Singapore",				"Asia/Saigon", "America/Santiago" });		tempMap.put("SRT", new String[] { "America/Paramaribo" });		tempMap.put("SST",				new String[] { "Pacific/Pago_Pago", "Pacific/Midway" });		tempMap.put("SVEMT", new String[] { "Asia/Yekaterinburg" });		tempMap.put("SVEST", new String[] { "Asia/Yekaterinburg" });		tempMap.put("SVET", new String[] { "Asia/Yekaterinburg" });		tempMap.put("SWAT", new String[] { "Africa/Windhoek" });		tempMap.put("SYOT", new String[] { "Antarctica/Syowa" });		tempMap.put("TAHT", new String[] { "Pacific/Tahiti" });		tempMap				.put("TASST",						new String[] { "Asia/Samarkand", "Asia/Tashkent" });		tempMap.put("TAST", new String[] { "Asia/Samarkand", "Asia/Tashkent" });		tempMap.put("TBIST", new String[] { "Asia/Tbilisi" });		tempMap.put("TBIT", new String[] { "Asia/Tbilisi" });		tempMap.put("TBMT", new String[] { "Asia/Tbilisi" });		tempMap.put("TFT", new String[] { "Indian/Kerguelen" });		tempMap.put("TJT", new String[] { "Asia/Dushanbe" });		tempMap.put("TKT", new String[] { "Pacific/Fakaofo" });		tempMap.put("TMST", new String[] { "Asia/Ashkhabad" });		tempMap.put("TMT", new String[] { "Europe/Tallinn", "Asia/Tehran",				"Asia/Ashkhabad" });		tempMap.put("TOST", new String[] { "Pacific/Tongatapu" });		tempMap.put("TOT", new String[] { "Pacific/Tongatapu" });		tempMap.put("TPT", new String[] { "Asia/Dili" });		tempMap.put("TRST", new String[] { "Europe/Istanbul" });		tempMap.put("TRT", new String[] { "Europe/Istanbul" });		tempMap.put("TRUT", new String[] { "Pacific/Truk" });		tempMap.put("TVT", new String[] { "Pacific/Funafuti" });		tempMap.put("ULAST", new String[] { "Asia/Ulaanbaatar" });		tempMap.put("ULAT", new String[] { "Asia/Ulaanbaatar" });		tempMap.put("URUT", new String[] { "Asia/Urumqi" });		tempMap.put("UYHST", new String[] { "America/Montevideo" });		tempMap.put("UYT", new String[] { "America/Montevideo" });		tempMap.put("UZST", new String[] { "Asia/Samarkand", "Asia/Tashkent" });		tempMap.put("UZT", new String[] { "Asia/Samarkand", "Asia/Tashkent" });		tempMap.put("VET", new String[] { "America/Caracas" });		tempMap.put("VLAMT", new String[] { "Asia/Vladivostok" });		tempMap.put("VLAST", new String[] { "Asia/Vladivostok" });		tempMap.put("VLAT", new String[] { "Asia/Vladivostok" });		tempMap.put("VUST", new String[] { "Pacific/Efate" });		tempMap.put("VUT", new String[] { "Pacific/Efate" });		tempMap.put("WAKT", new String[] { "Pacific/Wake" });		tempMap.put("WARST",				new String[] { "America/Jujuy", "America/Mendoza" });		tempMap				.put("WART",						new String[] { "America/Jujuy", "America/Mendoza" });		tempMap.put("WAST",				new String[] { "Africa/Ndjamena", "Africa/Windhoek" });		tempMap.put("WAT", new String[] { "Africa/Luanda", "Africa/Porto-Novo",				"Africa/Douala", "Africa/Bangui", "Africa/Ndjamena",				"Africa/Kinshasa", "Africa/Brazzaville", "Africa/Malabo",				"Africa/Libreville", "Africa/Banjul", "Africa/Conakry",				"Africa/Bissau", "Africa/Bamako", "Africa/Nouakchott",				"Africa/El_Aaiun", "Africa/Windhoek", "Africa/Niamey",				"Africa/Lagos", "Africa/Dakar", "Africa/Freetown" });		tempMap.put("WEST", new String[] { "Atlantic/Faeroe",				"Atlantic/Azores", "Atlantic/Madeira", "Atlantic/Canary",				"Europe/Brussels", "Europe/Luxembourg", "Europe/Monaco",				"Europe/Lisbon", "Europe/Madrid", "Africa/Algiers",				"Africa/Casablanca", "Africa/Ceuta" });		tempMap.put("WET", new String[] { "Atlantic/Faeroe", "Atlantic/Azores",				"Atlantic/Madeira", "Atlantic/Canary", "Europe/Andorra",				"Europe/Brussels", "Europe/Luxembourg", "Europe/Monaco",				"Europe/Lisbon", "Europe/Madrid", "Africa/Algiers",				"Africa/Casablanca", "Africa/El_Aaiun", "Africa/Ceuta" });		tempMap.put("WFT", new String[] { "Pacific/Wallis" });		tempMap.put("WGST", new String[] { "America/Godthab" });		tempMap.put("WGT", new String[] { "America/Godthab" });		tempMap.put("WMT", new String[] { "Europe/Vilnius", "Europe/Warsaw" });		tempMap.put("WST", new String[] { "Antarctica/Casey", "Pacific/Apia",				"Australia/Perth" });		tempMap.put("YAKMT", new String[] { "Asia/Yakutsk" });		tempMap.put("YAKST", new String[] { "Asia/Yakutsk" });		tempMap.put("YAKT", new String[] { "Asia/Yakutsk" });		tempMap.put("YAPT", new String[] { "Pacific/Yap" });		tempMap.put("YDDT", new String[] { "America/Whitehorse",				"America/Dawson" });		tempMap.put("YDT", new String[] { "America/Yakutat",				"America/Whitehorse", "America/Dawson" });		tempMap.put("YEKMT", new String[] { "Asia/Yekaterinburg" });		tempMap.put("YEKST", new String[] { "Asia/Yekaterinburg" });		tempMap.put("YEKT", new String[] { "Asia/Yekaterinburg" });		tempMap.put("YERST", new String[] { "Asia/Yerevan" });		tempMap.put("YERT", new String[] { "Asia/Yerevan" });		tempMap.put("YST", new String[] { "America/Yakutat",				"America/Whitehorse", "America/Dawson" });		tempMap.put("YWT", new String[] { "America/Yakutat" });		ABBREVIATED_TIMEZONES = Collections.unmodifiableMap(tempMap);	}	/**	 * Change the given times from one timezone to another	 * 	 * @param conn	 *            the current connection to the MySQL server	 * @param t	 *            the times to change	 * @param fromTz	 *            the timezone to change from	 * @param toTz	 *            the timezone to change to	 * 	 * @return the times changed to the timezone 'toTz'	 */	public static Time changeTimezone(ConnectionImpl conn,			Calendar sessionCalendar, 			Calendar targetCalendar, 			Time t, 			TimeZone fromTz,			TimeZone toTz, 			boolean rollForward) {		if ((conn != null)) {			if (conn.getUseTimezone() &&				!conn.getNoTimezoneConversionForTimeType()) {				// Convert the timestamp from GMT to the server's timezone				Calendar fromCal = Calendar.getInstance(fromTz);				fromCal.setTime(t);					int fromOffset = fromCal.get(Calendar.ZONE_OFFSET)						+ fromCal.get(Calendar.DST_OFFSET);				Calendar toCal = Calendar.getInstance(toTz);				toCal.setTime(t);					int toOffset = toCal.get(Calendar.ZONE_OFFSET)						+ toCal.get(Calendar.DST_OFFSET);				int offsetDiff = fromOffset - toOffset;				long toTime = toCal.getTime().getTime();					if (rollForward || (conn.isServerTzUTC() && !conn.isClientTzUTC())) {					toTime += offsetDiff;				} else {					toTime -= offsetDiff;				}					Time changedTime = new Time(toTime);					return changedTime;			}  else if (conn.getUseJDBCCompliantTimezoneShift()) {				if (targetCalendar != null) {					Time adjustedTime = new Time( 							jdbcCompliantZoneShift(sessionCalendar, 									targetCalendar, t));										return adjustedTime;				}			}		}				return t;	}	/**	 * Change the given timestamp from one timezone to another	 * 	 * @param conn	 *            the current connection to the MySQL server	 * @param tstamp	 *            the timestamp to change	 * @param fromTz	 *            the timezone to change from	 * @param toTz	 *            the timezone to change to	 * 	 * @return the timestamp changed to the timezone 'toTz'	 */	public static Timestamp changeTimezone(ConnectionImpl conn, 			Calendar sessionCalendar, 			Calendar targetCalendar, 			Timestamp tstamp,			TimeZone fromTz, 			TimeZone toTz, 			boolean rollForward) {		if ((conn != null)) {			if (conn.getUseTimezone()) {				// Convert the timestamp from GMT to the server's timezone				Calendar fromCal = Calendar.getInstance(fromTz);				fromCal.setTime(tstamp);					int fromOffset = fromCal.get(Calendar.ZONE_OFFSET)						+ fromCal.get(Calendar.DST_OFFSET);				Calendar toCal = Calendar.getInstance(toTz);				toCal.setTime(tstamp);					int toOffset = toCal.get(Calendar.ZONE_OFFSET)						+ toCal.get(Calendar.DST_OFFSET);				int offsetDiff = fromOffset - toOffset;				long toTime = toCal.getTime().getTime();					if (rollForward || (conn.isServerTzUTC() && !conn.isClientTzUTC())) {					toTime += offsetDiff;				} else {					toTime -= offsetDiff;				}					Timestamp changedTimestamp = new Timestamp(toTime);					return changedTimestamp;			} else if (conn.getUseJDBCCompliantTimezoneShift()) {				if (targetCalendar != null) {					Timestamp adjustedTimestamp = new Timestamp( 							jdbcCompliantZoneShift(sessionCalendar, 									targetCalendar, tstamp));										adjustedTimestamp.setNanos(tstamp.getNanos());										return adjustedTimestamp;				}			}		}				return tstamp;	}	private static long jdbcCompliantZoneShift(Calendar sessionCalendar, 			Calendar targetCalendar, 			java.util.Date dt) {		if (sessionCalendar == null) {			sessionCalendar = new GregorianCalendar();		}				// JDBC spec is not clear whether or not this 		// calendar should be immutable, so let's treat		// it like it is, for safety				java.util.Date origCalDate = targetCalendar.getTime();		java.util.Date origSessionDate = sessionCalendar.getTime();				try {			sessionCalendar.setTime(dt);						targetCalendar.set(Calendar.YEAR, sessionCalendar.get(Calendar.YEAR));			targetCalendar.set(Calendar.MONTH, sessionCalendar.get(Calendar.MONTH));			targetCalendar.set(Calendar.DAY_OF_MONTH, sessionCalendar.get(Calendar.DAY_OF_MONTH));			targetCalendar.set(Calendar.HOUR_OF_DAY, sessionCalendar.get(Calendar.HOUR_OF_DAY));                			targetCalendar.set(Calendar.MINUTE, sessionCalendar.get(Calendar.MINUTE));			targetCalendar.set(Calendar.SECOND, sessionCalendar.get(Calendar.SECOND));			targetCalendar.set(Calendar.MILLISECOND, sessionCalendar.get(Calendar.MILLISECOND));                						return targetCalendar.getTime().getTime();					} finally {			sessionCalendar.setTime(origSessionDate);			targetCalendar.setTime(origCalDate);		}	}	//	// WARN! You must externally synchronize these calendar instances	// See ResultSet.fastDateCreate() for an example	//

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -