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

📄 timeutil.java

📁 基于java的oa系统
💻 JAVA
📖 第 1 页 / 共 4 页
字号:
        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);    }    /**     * Returns the 'official' Java timezone name for the given timezone     *     * @param timezoneStr the 'common' timezone name     *     * @return the Java timezone name for the given timezone     */    public static String getCanoncialTimezone(String timezoneStr) {        if (timezoneStr == null) {            return null;        }        timezoneStr = timezoneStr.trim();        // Fix windows Daylight/Standard shift JDK doesn't map these (doh)        String timezoneStrUC = timezoneStr.toUpperCase();        int daylightIndex = timezoneStrUC.indexOf("DAYLIGHT");        if (daylightIndex != -1) {            StringBuffer timezoneBuf = new StringBuffer();            timezoneBuf.append(timezoneStr.substring(0, daylightIndex));            timezoneBuf.append("Standard");            timezoneBuf.append(timezoneStr.substring(daylightIndex                    + "DAYLIGHT".length(), timezoneStr.length()));            timezoneStr = timezoneBuf.toString();        }        String canonicalTz = (String) TIMEZONE_MAPPINGS.get(timezoneStr);        // if we didn't find it, try abbreviated timezones        if (canonicalTz == null) {            String[] abbreviatedTimezone = (String[]) ABBREVIATED_TIMEZONES.get(timezoneStr);            if (abbreviatedTimezone != null) {                // If there's only one mapping use that                if (abbreviatedTimezone.length == 1) {                    canonicalTz = abbreviatedTimezone[0];                } else {                    StringBuffer errorMsg = new StringBuffer(                            "The server timezone value '");                    errorMsg.append(timezoneStr);                    errorMsg.append(                        "' represents more than one timezone. You must ");                    errorMsg.append(                        "configure either the server or client to use a ");                    errorMsg.append(                        "more specifc timezone value if you want to enable ");                    errorMsg.append("timezone support. The timezones that '");                    errorMsg.append(timezoneStr);                    errorMsg.append("maps to are: ");                    errorMsg.append(abbreviatedTimezone[0]);                    for (int i = 1; i < abbreviatedTimezone.length; i++) {                        errorMsg.append(", ");                        errorMsg.append(abbreviatedTimezone[i]);                    }                    throw new IllegalArgumentException(errorMsg.toString());                }            }        }        return canonicalTz;    }    /**     * 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(Connection conn, Timestamp tstamp,        TimeZone fromTz, TimeZone toTz) {        if ((conn != null) && conn.useTimezone()) {            // 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; //toOffset - fromOffset;            long toTime = toCal.getTime().getTime();            toTime += offsetDiff;            Timestamp changedTimestamp = new Timestamp(toTime);            return changedTimestamp;        } else {            return tstamp;        }    }    /**     * 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(Connection conn, Time t, TimeZone fromTz,        TimeZone toTz) {        if ((conn != null) && conn.useTimezone()) {            // 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 = toOffset - fromOffset;            long toTime = toCal.getTime().getTime();            toTime += offsetDiff;            Time changedTime = new Time(toTime);            return changedTime;        } else {            return t;        }    }}

⌨️ 快捷键说明

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