Java Time related content learning (7) TimeZone Introduction

Source: Internet
Author: User
Tags abstract date final time zones locale

This chapter describes timezone.

TimeZone Introduction

TimeZone represents the time zone offset, or it can calculate daylight savings.

TimeZone is often used when manipulating dates, calendar, and so on to represent date/time objects, because of different time zones.

Here are 2 common ways to create timezone objects.

1 Get the default TimeZone object

How to use:

TimeZone TZ = Timezone.getdefault ()

2 using the getTimeZone (String id) method to get the TimeZone object

How to use:

Get the time zone corresponding to "gmt+08:00"

TimeZone-Timezone.gettimezone ("gmt+:08:00");

Get the "China/Chongqing" corresponding time zone

TimeZone chongqing = Timezone.gettimezone ("asia/chongqing");

The value of all ID parameters supported in this way by getTimeZone (String ID) can be found in the following ways:

string[] ids = Timezone.getavailableids ();

for (String id:ids)

System.out.printf (id+ ",");

Output results:

Etc/gmt+12, Etc/gmt+11, Pacific/midway, Pacific/niue, Pacific/pago_pago, Pacific/samoa, US/Samoa, America/Adak, America/atka, etc/gmt+10, HST, Pacific/honolulu, Pacific/johnston, Pacific/rarotonga, Pacific/tahiti, SystemV/HST10, Us/aleutian, Us/hawaii, Pacific/marquesas, AST, America/anchorage, America/juneau, America/nome, America/Sitka, America/yakutat, Etc/gmt+9, Pacific/gambier, Systemv/yst9, Systemv/yst9ydt, Us/alaska, America/Dawson, America/ Ensenada, America/los_angeles, America/metlakatla, America/santa_isabel, America/tijuana, America/vancouver, America /whitehorse, Canada/pacific, Canada/yukon, Etc/gmt+8, Mexico/bajanorte, PST, PST8PDT, Pacific/pitcairn, SystemV/PST8, SYSTEMV/PST8PDT, Us/pacific, Us/pacific-new, America/boise, America/cambridge_bay, America/chihuahua, America/ Creston, America/dawson_creek, America/denver, America/edmonton, America/hermosillo, America/Inuvik, America/ Mazatlan, America/ojinaga, America/phoenix, America/shiprock, America/yellowknife, Canada/mounTain, Etc/gmt+7, MST, MST7MDT, Mexico/bajasur, Navajo, PNT, Systemv/mst7, SYSTEMV/MST7MDT, Us/arizona, Us/mountain, Ameri Ca/bahia_banderas, America/belize, America/cancun, America/chicago, America/costa_rica, America/El_Salvador, America /guatemala, America/indiana/knox, america/indiana/tell_city, america/knox_in, America/managua, America/Matamoros, America/menominee, America/merida, america/mexico_city, America/monterrey, America/north_dakota/beulah, America/ North_dakota/center, America/north_dakota/new_salem, America/rainy_river, America/rankin_inlet, America/Regina, America/resolute, America/swift_current, America/tegucigalpa, America/winnipeg, CST, CST6CDT, Canada/Central, Canada/ East-saskatchewan, Canada/saskatchewan, Chile/easterisland, Etc/gmt+6, Mexico/general, Pacific/Easter, Pacific/ Galapagos, Systemv/cst6, SYSTEMV/CST6CDT, Us/central, Us/indiana-starke, America/atikokan, America/Bogota, America/ Cayman, America/coral_harbour, America/detroit, America/fort_wayne, America/grand_Turk, America/guayaquil, America/havana, America/indiana/indianapolis, America/indiana/marengo, America/Indiana/ Petersburg, America/indiana/vevay, America/indiana/vincennes, America/indiana/winamac, America/indianapolis, America/iqaluit, America/jamaica, America/kentucky/louisville, America/kentucky/monticello, America/Lima, America/ Louisville, America/montreal, America/nassau, America/new_york, America/nipigon, America/panama, America/Pangnirtung , America/port-au-prince, America/thunder_bay, America/toronto, Canada/eastern, Cuba, EST, Est5edt, Etc/GMT+5, IET, Jamaica, SYSTEMV/EST5, Systemv/est5edt, Us/east-indiana, Us/eastern, Us/michigan, America/caracas, America/Anguilla, America/antigua, America/argentina/san_luis, America/aruba, America/asuncion, America/barbados, America/ Blanc-sablon, America/boa_vista, America/campo_grande, America/cuiaba, America/curacao, America/Dominica, America/ Eirunepe, America/glace_bay, America/goose_bay, America/grenada, America/guadeloupe, America/GuyanA, America/halifax, America/kralendijk, America/la_paz, America/lower_princes, America/manaus, America/Marigot, America/martinique, America/moncton, America/montserrat, America/port_of_spain, America/porto_acre, America/Porto_ Velho, America/puerto_rico, America/rio_branco, America/santiago, America/santo_domingo, America/st_barthelemy, America/st_kitts, America/st_lucia, America/st_thomas, America/st_vincent, America/thule, America/Tortola, America/ Virgin, Antarctica/palmer, Atlantic/bermuda, Brazil/acre, Brazil/west, Canada/atlantic, Chile/continental, Etc/GMT+4, PRT, Systemv/ast4, Systemv/ast4adt, America/st_johns, CNT, Canada/newfoundland, AGT, America/araguaina, America/ Argentina/buenos_aires, America/argentina/catamarca, America/argentina/comodrivadavia, America/Argentina/Cordoba, America/argentina/jujuy, America/argentina/la_rioja, America/argentina/mendoza, America/argentina/rio_gallegos, America/argentina/salta, America/argentina/san_juan, America/argentina/tucuman, America/argEntina/ushuaia, America/bahia, America/belem, America/buenos_aires, America/catamarca, America/Cayenne, America/ Cordoba, America/fortaleza, America/godthab, America/jujuy, America/maceio, America/mendoza, America/miquelon, America/montevideo, America/paramaribo, America/recife, America/rosario, America/santarem, America/Sao_Paulo, Antarctica/rothera, Atlantic/stanley, BET, Brazil/east, Etc/gmt+3, America/noronha, Atlantic/south_georgia, Brazil/ Denoronha, Etc/gmt+2, America/scoresbysund, Atlantic/azores, Atlantic/cape_verde, etc/gmt+1, Africa/Abidjan, Africa/ ACCRA, Africa/bamako, Africa/banjul, Africa/bissau, Africa/casablanca, Africa/conakry, Africa/dakar, Africa/El_Aaiun, Africa/freetown, Africa/lome, Africa/monrovia, Africa/nouakchott, Africa/ouagadougou, Africa/Sao_Tome, Africa/ Timbuktu, America/danmarkshavn, Atlantic/canary, Atlantic/faeroe, Atlantic/faroe, Atlantic/madeira, Atlantic/ Reykjavik, Atlantic/st_helena, Eire, Etc/gmt, etc/gmt+0, etc/gmt-0, Etc/gmt0, Etc/greenwich, Etc/ucT, ETC/UTC, Etc/universal, Etc/zulu, Europe/belfast, Europe/dublin, Europe/guernsey, Europe/isle_of_man, Europe/Jersey , Europe/lisbon, Europe/london, GB, Gb-eire, GMT, GMT0, Greenwich, Iceland, Portugal, UCT, UTC, Universal, WET, Zulu, Afri Ca/algiers, Africa/bangui, Africa/brazzaville, Africa/ceuta, Africa/douala, Africa/kinshasa, Africa/Lagos, Africa/ Libreville, Africa/luanda, Africa/malabo, Africa/ndjamena, Africa/niamey, Africa/porto-novo, Africa/Tunis, Africa/ Windhoek, Arctic/longyearbyen, Atlantic/jan_mayen, CET, ECT, Etc/gmt-1, Europe/amsterdam, Europe/andorra, Europe/ Belgrade, Europe/berlin, Europe/bratislava, Europe/brussels, Europe/budapest, Europe/copenhagen, Europe/Gibraltar, Europe/ljubljana, Europe/luxembourg, Europe/madrid, Europe/malta, Europe/monaco, Europe/oslo, Europe/Paris, Europe/ Podgorica, Europe/prague, Europe/rome, Europe/san_marino, Europe/sarajevo, Europe/skopje, Europe/stockholm, Europe/ Tirane, Europe/vaduz, Europe/vatican, Europe/vienna, Europe/warsaw, Europe/zagreb, Europe/zurich, MET, Poland, ART, Africa/blantyre, Africa/bujumbura, Africa/cairo, Africa/gaborone, Africa/ Harare, Africa/johannesburg, Africa/kigali, Africa/lubumbashi, Africa/lusaka, Africa/maputo, Africa/Maseru, Africa/ Mbabane, Africa/tripoli, Asia/amman, Asia/beirut, Asia/damascus, Asia/gaza, Asia/hebron, Asia/Istanbul, Asia/Jerusalem , Asia/nicosia, Asia/tel_aviv, CAT, EET, Egypt, Etc/gmt-2, Europe/athens, Europe/bucharest, Europe/chisinau, Europe/ Helsinki, Europe/istanbul, Europe/kiev, Europe/mariehamn, Europe/nicosia, Europe/riga, Europe/simferopol, Europe/ Sofia, Europe/tallinn, Europe/tiraspol, Europe/uzhgorod, Europe/vilnius, Europe/zaporozhye, Israel, Libya, Turkey, Africa/addis_ababa, Africa/asmara, Africa/asmera, Africa/dar_es_salaam, Africa/djibouti, Africa/Juba, Africa/Kampala , Africa/khartoum, Africa/mogadishu, Africa/nairobi, Antarctica/syowa, Asia/aden, Asia/baghdad, Asia/Bahrain, Asia/ Kuwait, Asia/qatar, Asia/riyadh, EAT, etc/gmt-3, Europe/kaliningrad, europe/mInsk, Indian/antananarivo, Indian/comoro, Indian/mayotte, asia/riyadh87, asia/riyadh88, Asia/Riyadh89, Mideast/ Riyadh87, Mideast/riyadh88, mideast/riyadh89, Asia/tehran, Iran, Asia/baku, Asia/dubai, Asia/muscat, Asia/tbilisi, Asia /yerevan, Etc/gmt-4, Europe/moscow, Europe/samara, Europe/volgograd, Indian/mahe, Indian/mauritius, Indian/Reunion, NET, W-su, Asia/kabul, Antarctica/mawson, Asia/aqtau, Asia/aqtobe, Asia/ashgabat, Asia/ashkhabad, Asia/Dushanbe, Asia/ Karachi, Asia/oral, Asia/samarkand, Asia/tashkent, etc/gmt-5, Indian/kerguelen, Indian/maldives, PLT, Asia/Calcutta, Asia/colombo, Asia/kolkata, IST, Asia/kathmandu, Asia/katmandu, Antarctica/vostok, Asia/almaty, Asia/Bishkek, Asia/ Dacca, Asia/dhaka, Asia/qyzylorda, Asia/thimbu, Asia/thimphu, Asia/yekaterinburg, BST, etc/gmt-6, Indian/Chagos, Asia/ Rangoon, Indian/cocos, Antarctica/davis, Asia/bangkok, Asia/ho_chi_minh, Asia/hovd, Asia/jakarta, Asia/Novokuznetsk, Asia/novosibirsk, Asia/omsk, Asia/phnom_penh, Asia/pontianak, Asia/saIgon, Asia/vientiane, etc/gmt-7, Indian/christmas, VST, Antarctica/casey, Asia/brunei, Asia/choibalsan, Asia/Chongqing , Asia/chungking, Asia/harbin, Asia/hong_kong, Asia/kashgar, Asia/krasnoyarsk, Asia/kuala_lumpur, Asia/Kuching, Asia/ Macao, Asia/macau, Asia/makassar, Asia/manila, Asia/shanghai, Asia/singapore, Asia/taipei, Asia/Ujung_Pandang, Asia/ Ulaanbaatar, Asia/ulan_bator, Asia/urumqi, Australia/perth, Australia/west, CTT, Etc/gmt-8, Hongkong, PRC, Singapore, Australia/eucla, Asia/dili, Asia/irkutsk, Asia/jayapura, Asia/pyongyang, Asia/seoul, Asia/tokyo, Etc/GMT-9, JST, Japan, Pacific/palau, ROK, ACT, Australia/adelaide, Australia/broken_hill, Australia/darwin, Australia/north, Australia/ South, Australia/yancowinna, AET, Antarctica/dumontdurville, Asia/yakutsk, Australia/act, Australia/brisbane, Australia/canberra, Australia/currie, Australia/hobart, Australia/lindeman, Australia/melbourne, Australia/NSW, Australia/queensland, Australia/sydney, Australia/tasmania, Australia/victorIA, etc/gmt-10, Pacific/chuuk, Pacific/guam, Pacific/port_moresby, Pacific/saipan, Pacific/truk, Pacific/Yap, Australia/lhi, Australia/lord_howe, Antarctica/macquarie, Asia/sakhalin, Asia/vladivostok, Etc/GMT-11, Pacific/Efate , Pacific/guadalcanal, Pacific/kosrae, Pacific/noumea, Pacific/pohnpei, Pacific/ponape, SST, Pacific/Norfolk, Antarctica/mcmurdo, Antarctica/south_pole, Asia/anadyr, Asia/kamchatka, Asia/magadan, Etc/GMT-12, Kwajalein, NST, NZ, Pacific/auckland, Pacific/fiji, Pacific/funafuti, Pacific/kwajalein, Pacific/majuro, Pacific/Nauru, Pacific/Tarawa, Pacific/wake, Pacific/wallis, Nz-chat, Pacific/chatham, etc/gmt-13, MIT, Pacific/apia, Pacific/enderbury, Pacific/ Fakaofo, Pacific/tongatapu, etc/gmt-14, Pacific/kiritimati

For example, create a timezone corresponding to the 2nd printed value "Etc/gmt+11" above. The method is as follows:

TimeZone TZ = Timezone.gettimezone ("etc/gmt+11");

function interface of timezone

Constructor TimeZone () Object clone () synchronized static string[] Getavailableids () sync hronized Static string[] getavailableids (int offsetmillis) int getdstsavings () Synchroniz                           Ed static TimeZone Getdefault () Final string GetDisplayName (Locale Locale) string 
GetDisplayName (boolean daylighttime, int style, Locale Locale) Final String GetDisplayName () 
Final String GetDisplayName (boolean daylighttime, int style) String GetID ()                               abstract int getoffset (int era, year of int, int month, int day, int dayofweek, int timeofdaymillis) int GetOffset (long time) abstract int getrawoffset () synchronized static Tim                 EZone getTimeZone (String id) boolean hassamerules (TimeZone TimeZone) Abstract Boolean Indaylighttime (Date time) synchronized static void SetDefault (TimeZone TimeZone) void SetID (String ID abstract void Setrawoffset (int offsetmillis) Abstract Boolean usedaylighttime ()

Related Article

Beyond APAC's No.1 Cloud

19.6% IaaS Market Share in Asia Pacific - Gartner IT Service report, 2018

Learn more >

Apsara Conference 2019

The Rise of Data Intelligence, September 25th - 27th, Hangzhou, China

Learn more >

Alibaba Cloud Free Trial

Learn and experience the power of Alibaba Cloud with a free trial worth $300-1200 USD

Learn more >

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.