Java Date

  1. Create a simple Date function in Java
  2. Compare two Dates in Different manner in Java
  3. Set Simple Date Format in Java
  4. Set Simple Time Format in Java
  5. Get All TimeZone ID in Java
  6. Add Months to Calendar in Java
  7. Subtract Months to Calendar in Java
  8. Add Day, Month & Year to Calendar in Java

Note
Here I am using,
OS : Linux (Ubuntu 12.04)
IDE : Eclipse Tool
Eclipse : Juno (Version 4.2.0)
Package : Default package

A. Create a simple Date function in Java


Date_Ex1.java

import java.util.Date;
 
public class Date_Ex1 {
	
	Date dt;
	
	void method1() {
		
		System.out.println("Date Method - 1");
		
		dt = new java.util.Date();
		System.out.println(dt);
	}
	
	void method2() {
		
		System.out.println("\nDate Method - 2");
		
		dt = new java.util.Date(91, 9, 7);
		System.out.println(dt);
	}
	
	void method3() {
		
		System.out.println("\nDate Method - 3");
		
		dt = new java.util.Date(91, 9, 7, 11, 10);
		System.out.println(dt);
	}
	
	void method4() {
		
		System.out.println("\nDate Method - 4");
		
		dt = new java.util.Date(91, 9, 7, 11, 10, 56);
		System.out.println(dt);
	}
}
 
class MainClass {
	
	public static void main(String args[]) {
		
		Date_Ex1 obj = new Date_Ex1();
		
		obj.method1();
		obj.method2();
		obj.method3();
		obj.method4();
	}
}

Sample Output

Date Method - 1
Sat Jan 26 12:05:33 IST 2013

Date Method - 2
Mon Oct 07 00:00:00 IST 1991

Date Method - 3
Mon Oct 07 11:10:00 IST 1991

Date Method - 4
Mon Oct 07 11:10:56 IST 1991




B. Compare two Dates in Different manner in Java


Date_Ex2.java

import java.util.Date;
 
public class Date_Ex2 {
 
	Date date1, date2;
	
	void getDate() {
		
		date1 = new Date();
		
		try {
			Thread.sleep(1000);
		}
		catch (Exception e) {
			System.out.println("Error : " + e.toString());
		}
		finally {
			date2 = new Date();
		}
		
		
		System.out.println("\nDate-1 : " + date1);
		System.out.println("Date-2 : " + date2);
	}
	
	void compare_1() {
		
		System.out.println("\nDate comparision method - 1");
 
		if(date1.after(date2))
			System.out.println("Date2 - First..");
		else
			System.out.println("Date1 - First..");
	}
	
	void compare_2() {
		
		System.out.println("\nDate comparision method - 2");
 
		if(date1.before(date2))
			System.out.println("Date1 - First..");
		else
			System.out.println("Date2 - First..");
	}
	
	void compare_3() {
		
		System.out.println("\nDate comparision method - 3");
 
		if(date1.compareTo(date2) < 0)
			System.out.println("Date1 - First..");
		else if(date1.compareTo(date2) > 0)
			System.out.println("Date2 - First..");
		else
			System.out.println("Date1 & Date2 both are equal");
	}
}
 
class MainClass {
	
	public static void main(String args[]) {
		
		Date_Ex2 obj = new Date_Ex2();
		
		obj.getDate();
		
		obj.compare_1();
		obj.compare_2();
		obj.compare_3();
	}
}

Sample Output


Date-1 : Sat Jan 26 12:06:32 IST 2013
Date-2 : Sat Jan 26 12:06:33 IST 2013

Date comparision method - 1
Date1 - First..

Date comparision method - 2
Date1 - First..

Date comparision method - 3
Date1 - First..




C. Set Simple Date Format in Java


Date_Ex3.java

import java.text.SimpleDateFormat;
import java.util.Date;
 
public class Date_Ex3 {
 
	Date dt;
	SimpleDateFormat format;
	
	void without() {
		
		dt = new Date();
		System.out.println("Without Format : " + dt);
	}
	
	void with1() {
		
		format = new SimpleDateFormat("dd-MM-yyyy");
		String date = format.format(dt);
		
		System.out.println("With Format : " + date);
	}
	
	void with2() {
		
		format = new SimpleDateFormat("dd/MM/yyyy");
		String date = format.format(dt);
		
		System.out.println("With Format : " + date);
	}
}
 
class MainClass {
	
	public static void main(String args[]) {
		
		Date_Ex3 obj = new Date_Ex3();
		
		obj.without();
		obj.with1();
		obj.with2();
	}
}

Sample Output

Without Format : Sat Jan 26 12:06:58 IST 2013
With Format : 26-01-2013
With Format : 26/01/2013




D. Set Simple Time Format in Java


Date_Ex4.java

import java.text.Format;
import java.text.SimpleDateFormat;
import java.util.Date;
 
public class Date_Ex4 {
 
	Date dt;
	Format format;
	
	void without() {
		
		dt = new Date();
		System.out.println("Without Format : " + dt);
	}
	
	void with1() {
 
		format = new SimpleDateFormat("hh:mm:ss");
		String time = format.format(dt);
		
		System.out.println("With Format : " + time);
	}
	
	void with2() {
		
		format = new SimpleDateFormat("hh-mm-ss a");
		String time = format.format(dt);
		
		System.out.println("With Format : " + time);
	}
}
 
class MainClass {
	
	public static void main(String args[]) {
		
		Date_Ex4 obj = new Date_Ex4();
		
		obj.without();
		obj.with1();
		obj.with2();
	}
}

Sample Output

Without Format : Sat Jan 26 12:07:15 IST 2013
With Format : 12:07:15
With Format : 12-07-15 PM




E. Get All TimeZone ID in Java


Date_Ex5.java

import java.util.TimeZone;
 
public class Date_Ex5 {
 
	public static void main(String args[]) {
		
		String[] timeZone = TimeZone.getAvailableIDs();
		
		for(int i=0; i<timeZone.length; i++) {
			
			System.out.println(i+1 + " TimeZone ID : " + timeZone[i]);
		}
	}
}

Sample Output

1 TimeZone ID : Etc/GMT+12
2 TimeZone ID : Etc/GMT+11
3 TimeZone ID : Pacific/Midway
4 TimeZone ID : Pacific/Niue
5 TimeZone ID : Pacific/Pago_Pago
6 TimeZone ID : Pacific/Samoa
7 TimeZone ID : US/Samoa
8 TimeZone ID : America/Adak
9 TimeZone ID : America/Atka
10 TimeZone ID : Etc/GMT+10
11 TimeZone ID : HST
12 TimeZone ID : Pacific/Honolulu
13 TimeZone ID : Pacific/Johnston
14 TimeZone ID : Pacific/Rarotonga
15 TimeZone ID : Pacific/Tahiti
16 TimeZone ID : SystemV/HST10
17 TimeZone ID : US/Aleutian
18 TimeZone ID : US/Hawaii
19 TimeZone ID : Pacific/Marquesas
20 TimeZone ID : AST
21 TimeZone ID : America/Anchorage
22 TimeZone ID : America/Juneau
23 TimeZone ID : America/Nome
24 TimeZone ID : America/Sitka
25 TimeZone ID : America/Yakutat
26 TimeZone ID : Etc/GMT+9
27 TimeZone ID : Pacific/Gambier
28 TimeZone ID : SystemV/YST9
29 TimeZone ID : SystemV/YST9YDT
30 TimeZone ID : US/Alaska
31 TimeZone ID : America/Dawson
32 TimeZone ID : America/Ensenada
33 TimeZone ID : America/Los_Angeles
34 TimeZone ID : America/Metlakatla
35 TimeZone ID : America/Santa_Isabel
36 TimeZone ID : America/Tijuana
37 TimeZone ID : America/Vancouver
38 TimeZone ID : America/Whitehorse
39 TimeZone ID : Canada/Pacific
40 TimeZone ID : Canada/Yukon
41 TimeZone ID : Etc/GMT+8
42 TimeZone ID : Mexico/BajaNorte
43 TimeZone ID : PST
44 TimeZone ID : PST8PDT
45 TimeZone ID : Pacific/Pitcairn
46 TimeZone ID : SystemV/PST8
47 TimeZone ID : SystemV/PST8PDT
48 TimeZone ID : US/Pacific
49 TimeZone ID : US/Pacific-New
50 TimeZone ID : America/Boise
51 TimeZone ID : America/Cambridge_Bay
52 TimeZone ID : America/Chihuahua
53 TimeZone ID : America/Creston
54 TimeZone ID : America/Dawson_Creek
55 TimeZone ID : America/Denver
56 TimeZone ID : America/Edmonton
57 TimeZone ID : America/Hermosillo
58 TimeZone ID : America/Inuvik
59 TimeZone ID : America/Mazatlan
60 TimeZone ID : America/Ojinaga
61 TimeZone ID : America/Phoenix
62 TimeZone ID : America/Shiprock
63 TimeZone ID : America/Yellowknife
64 TimeZone ID : Canada/Mountain
65 TimeZone ID : Etc/GMT+7
66 TimeZone ID : MST
67 TimeZone ID : MST7MDT
68 TimeZone ID : Mexico/BajaSur
69 TimeZone ID : Navajo
70 TimeZone ID : PNT
71 TimeZone ID : SystemV/MST7
72 TimeZone ID : SystemV/MST7MDT
73 TimeZone ID : US/Arizona
74 TimeZone ID : US/Mountain
75 TimeZone ID : America/Bahia_Banderas
76 TimeZone ID : America/Belize
77 TimeZone ID : America/Cancun
78 TimeZone ID : America/Chicago
79 TimeZone ID : America/Costa_Rica
80 TimeZone ID : America/El_Salvador
81 TimeZone ID : America/Guatemala
82 TimeZone ID : America/Indiana/Knox
83 TimeZone ID : America/Indiana/Tell_City
84 TimeZone ID : America/Knox_IN
85 TimeZone ID : America/Managua
86 TimeZone ID : America/Matamoros
87 TimeZone ID : America/Menominee
88 TimeZone ID : America/Merida
89 TimeZone ID : America/Mexico_City
90 TimeZone ID : America/Monterrey
91 TimeZone ID : America/North_Dakota/Beulah
92 TimeZone ID : America/North_Dakota/Center
93 TimeZone ID : America/North_Dakota/New_Salem
94 TimeZone ID : America/Rainy_River
95 TimeZone ID : America/Rankin_Inlet
96 TimeZone ID : America/Regina
97 TimeZone ID : America/Resolute
98 TimeZone ID : America/Swift_Current
99 TimeZone ID : America/Tegucigalpa
100 TimeZone ID : America/Winnipeg
101 TimeZone ID : CST
102 TimeZone ID : CST6CDT
103 TimeZone ID : Canada/Central
104 TimeZone ID : Canada/East-Saskatchewan
105 TimeZone ID : Canada/Saskatchewan
106 TimeZone ID : Chile/EasterIsland
107 TimeZone ID : Etc/GMT+6
108 TimeZone ID : Mexico/General
109 TimeZone ID : Pacific/Easter
110 TimeZone ID : Pacific/Galapagos
111 TimeZone ID : SystemV/CST6
112 TimeZone ID : SystemV/CST6CDT
113 TimeZone ID : US/Central
114 TimeZone ID : US/Indiana-Starke
115 TimeZone ID : America/Atikokan
116 TimeZone ID : America/Bogota
117 TimeZone ID : America/Cayman
118 TimeZone ID : America/Coral_Harbour
119 TimeZone ID : America/Detroit
120 TimeZone ID : America/Fort_Wayne
121 TimeZone ID : America/Grand_Turk
122 TimeZone ID : America/Guayaquil
123 TimeZone ID : America/Havana
124 TimeZone ID : America/Indiana/Indianapolis
125 TimeZone ID : America/Indiana/Marengo
126 TimeZone ID : America/Indiana/Petersburg
127 TimeZone ID : America/Indiana/Vevay
128 TimeZone ID : America/Indiana/Vincennes
129 TimeZone ID : America/Indiana/Winamac
130 TimeZone ID : America/Indianapolis
131 TimeZone ID : America/Iqaluit
132 TimeZone ID : America/Jamaica
133 TimeZone ID : America/Kentucky/Louisville
134 TimeZone ID : America/Kentucky/Monticello
135 TimeZone ID : America/Lima
136 TimeZone ID : America/Louisville
137 TimeZone ID : America/Montreal
138 TimeZone ID : America/Nassau
139 TimeZone ID : America/New_York
140 TimeZone ID : America/Nipigon
141 TimeZone ID : America/Panama
142 TimeZone ID : America/Pangnirtung
143 TimeZone ID : America/Port-au-Prince
144 TimeZone ID : America/Thunder_Bay
145 TimeZone ID : America/Toronto
146 TimeZone ID : Canada/Eastern
147 TimeZone ID : Cuba
148 TimeZone ID : EST
149 TimeZone ID : EST5EDT
150 TimeZone ID : Etc/GMT+5
151 TimeZone ID : IET
152 TimeZone ID : Jamaica
153 TimeZone ID : SystemV/EST5
154 TimeZone ID : SystemV/EST5EDT
155 TimeZone ID : US/East-Indiana
156 TimeZone ID : US/Eastern
157 TimeZone ID : US/Michigan
158 TimeZone ID : America/Caracas
159 TimeZone ID : America/Anguilla
160 TimeZone ID : America/Antigua
161 TimeZone ID : America/Argentina/San_Luis
162 TimeZone ID : America/Aruba
163 TimeZone ID : America/Asuncion
164 TimeZone ID : America/Barbados
165 TimeZone ID : America/Blanc-Sablon
166 TimeZone ID : America/Boa_Vista
167 TimeZone ID : America/Campo_Grande
168 TimeZone ID : America/Cuiaba
169 TimeZone ID : America/Curacao
170 TimeZone ID : America/Dominica
171 TimeZone ID : America/Eirunepe
172 TimeZone ID : America/Glace_Bay
173 TimeZone ID : America/Goose_Bay
174 TimeZone ID : America/Grenada
175 TimeZone ID : America/Guadeloupe
176 TimeZone ID : America/Guyana
177 TimeZone ID : America/Halifax
178 TimeZone ID : America/Kralendijk
179 TimeZone ID : America/La_Paz
180 TimeZone ID : America/Lower_Princes
181 TimeZone ID : America/Manaus
182 TimeZone ID : America/Marigot
183 TimeZone ID : America/Martinique
184 TimeZone ID : America/Moncton
185 TimeZone ID : America/Montserrat
186 TimeZone ID : America/Port_of_Spain
187 TimeZone ID : America/Porto_Acre
188 TimeZone ID : America/Porto_Velho
189 TimeZone ID : America/Puerto_Rico
190 TimeZone ID : America/Rio_Branco
191 TimeZone ID : America/Santiago
192 TimeZone ID : America/Santo_Domingo
193 TimeZone ID : America/St_Barthelemy
194 TimeZone ID : America/St_Kitts
195 TimeZone ID : America/St_Lucia
196 TimeZone ID : America/St_Thomas
197 TimeZone ID : America/St_Vincent
198 TimeZone ID : America/Thule
199 TimeZone ID : America/Tortola
200 TimeZone ID : America/Virgin
201 TimeZone ID : Antarctica/Palmer
202 TimeZone ID : Atlantic/Bermuda
203 TimeZone ID : Brazil/Acre
204 TimeZone ID : Brazil/West
205 TimeZone ID : Canada/Atlantic
206 TimeZone ID : Chile/Continental
207 TimeZone ID : Etc/GMT+4
208 TimeZone ID : PRT
209 TimeZone ID : SystemV/AST4
210 TimeZone ID : SystemV/AST4ADT
211 TimeZone ID : America/St_Johns
212 TimeZone ID : CNT
213 TimeZone ID : Canada/Newfoundland
214 TimeZone ID : AGT
215 TimeZone ID : America/Araguaina
216 TimeZone ID : America/Argentina/Buenos_Aires
217 TimeZone ID : America/Argentina/Catamarca
218 TimeZone ID : America/Argentina/ComodRivadavia
219 TimeZone ID : America/Argentina/Cordoba
220 TimeZone ID : America/Argentina/Jujuy
221 TimeZone ID : America/Argentina/La_Rioja
222 TimeZone ID : America/Argentina/Mendoza
223 TimeZone ID : America/Argentina/Rio_Gallegos
224 TimeZone ID : America/Argentina/Salta
225 TimeZone ID : America/Argentina/San_Juan
226 TimeZone ID : America/Argentina/Tucuman
227 TimeZone ID : America/Argentina/Ushuaia
228 TimeZone ID : America/Bahia
229 TimeZone ID : America/Belem
230 TimeZone ID : America/Buenos_Aires
231 TimeZone ID : America/Catamarca
232 TimeZone ID : America/Cayenne
233 TimeZone ID : America/Cordoba
234 TimeZone ID : America/Fortaleza
235 TimeZone ID : America/Godthab
236 TimeZone ID : America/Jujuy
237 TimeZone ID : America/Maceio
238 TimeZone ID : America/Mendoza
239 TimeZone ID : America/Miquelon
240 TimeZone ID : America/Montevideo
241 TimeZone ID : America/Paramaribo
242 TimeZone ID : America/Recife
243 TimeZone ID : America/Rosario
244 TimeZone ID : America/Santarem
245 TimeZone ID : America/Sao_Paulo
246 TimeZone ID : Antarctica/Rothera
247 TimeZone ID : Atlantic/Stanley
248 TimeZone ID : BET
249 TimeZone ID : Brazil/East
250 TimeZone ID : Etc/GMT+3
251 TimeZone ID : America/Noronha
252 TimeZone ID : Atlantic/South_Georgia
253 TimeZone ID : Brazil/DeNoronha
254 TimeZone ID : Etc/GMT+2
255 TimeZone ID : America/Scoresbysund
256 TimeZone ID : Atlantic/Azores
257 TimeZone ID : Atlantic/Cape_Verde
258 TimeZone ID : Etc/GMT+1
259 TimeZone ID : Africa/Abidjan
260 TimeZone ID : Africa/Accra
261 TimeZone ID : Africa/Bamako
262 TimeZone ID : Africa/Banjul
263 TimeZone ID : Africa/Bissau
264 TimeZone ID : Africa/Casablanca
265 TimeZone ID : Africa/Conakry
266 TimeZone ID : Africa/Dakar
267 TimeZone ID : Africa/El_Aaiun
268 TimeZone ID : Africa/Freetown
269 TimeZone ID : Africa/Lome
270 TimeZone ID : Africa/Monrovia
271 TimeZone ID : Africa/Nouakchott
272 TimeZone ID : Africa/Ouagadougou
273 TimeZone ID : Africa/Sao_Tome
274 TimeZone ID : Africa/Timbuktu
275 TimeZone ID : America/Danmarkshavn
276 TimeZone ID : Atlantic/Canary
277 TimeZone ID : Atlantic/Faeroe
278 TimeZone ID : Atlantic/Faroe
279 TimeZone ID : Atlantic/Madeira
280 TimeZone ID : Atlantic/Reykjavik
281 TimeZone ID : Atlantic/St_Helena
282 TimeZone ID : Eire
283 TimeZone ID : Etc/GMT
284 TimeZone ID : Etc/GMT+0
285 TimeZone ID : Etc/GMT-0
286 TimeZone ID : Etc/GMT0
287 TimeZone ID : Etc/Greenwich
288 TimeZone ID : Etc/UCT
289 TimeZone ID : Etc/UTC
290 TimeZone ID : Etc/Universal
291 TimeZone ID : Etc/Zulu
292 TimeZone ID : Europe/Belfast
293 TimeZone ID : Europe/Dublin
294 TimeZone ID : Europe/Guernsey
295 TimeZone ID : Europe/Isle_of_Man
296 TimeZone ID : Europe/Jersey
297 TimeZone ID : Europe/Lisbon
298 TimeZone ID : Europe/London
299 TimeZone ID : GB
300 TimeZone ID : GB-Eire
301 TimeZone ID : GMT
302 TimeZone ID : GMT0
303 TimeZone ID : Greenwich
304 TimeZone ID : Iceland
305 TimeZone ID : Portugal
306 TimeZone ID : UCT
307 TimeZone ID : UTC
308 TimeZone ID : Universal
309 TimeZone ID : WET
310 TimeZone ID : Zulu
311 TimeZone ID : Africa/Algiers
312 TimeZone ID : Africa/Bangui
313 TimeZone ID : Africa/Brazzaville
314 TimeZone ID : Africa/Ceuta
315 TimeZone ID : Africa/Douala
316 TimeZone ID : Africa/Kinshasa
317 TimeZone ID : Africa/Lagos
318 TimeZone ID : Africa/Libreville
319 TimeZone ID : Africa/Luanda
320 TimeZone ID : Africa/Malabo
321 TimeZone ID : Africa/Ndjamena
322 TimeZone ID : Africa/Niamey
323 TimeZone ID : Africa/Porto-Novo
324 TimeZone ID : Africa/Tunis
325 TimeZone ID : Africa/Windhoek
326 TimeZone ID : Arctic/Longyearbyen
327 TimeZone ID : Atlantic/Jan_Mayen
328 TimeZone ID : CET
329 TimeZone ID : ECT
330 TimeZone ID : Etc/GMT-1
331 TimeZone ID : Europe/Amsterdam
332 TimeZone ID : Europe/Andorra
333 TimeZone ID : Europe/Belgrade
334 TimeZone ID : Europe/Berlin
335 TimeZone ID : Europe/Bratislava
336 TimeZone ID : Europe/Brussels
337 TimeZone ID : Europe/Budapest
338 TimeZone ID : Europe/Copenhagen
339 TimeZone ID : Europe/Gibraltar
340 TimeZone ID : Europe/Ljubljana
341 TimeZone ID : Europe/Luxembourg
342 TimeZone ID : Europe/Madrid
343 TimeZone ID : Europe/Malta
344 TimeZone ID : Europe/Monaco
345 TimeZone ID : Europe/Oslo
346 TimeZone ID : Europe/Paris
347 TimeZone ID : Europe/Podgorica
348 TimeZone ID : Europe/Prague
349 TimeZone ID : Europe/Rome
350 TimeZone ID : Europe/San_Marino
351 TimeZone ID : Europe/Sarajevo
352 TimeZone ID : Europe/Skopje
353 TimeZone ID : Europe/Stockholm
354 TimeZone ID : Europe/Tirane
355 TimeZone ID : Europe/Vaduz
356 TimeZone ID : Europe/Vatican
357 TimeZone ID : Europe/Vienna
358 TimeZone ID : Europe/Warsaw
359 TimeZone ID : Europe/Zagreb
360 TimeZone ID : Europe/Zurich
361 TimeZone ID : MET
362 TimeZone ID : Poland
363 TimeZone ID : ART
364 TimeZone ID : Africa/Blantyre
365 TimeZone ID : Africa/Bujumbura
366 TimeZone ID : Africa/Cairo
367 TimeZone ID : Africa/Gaborone
368 TimeZone ID : Africa/Harare
369 TimeZone ID : Africa/Johannesburg
370 TimeZone ID : Africa/Kigali
371 TimeZone ID : Africa/Lubumbashi
372 TimeZone ID : Africa/Lusaka
373 TimeZone ID : Africa/Maputo
374 TimeZone ID : Africa/Maseru
375 TimeZone ID : Africa/Mbabane
376 TimeZone ID : Africa/Tripoli
377 TimeZone ID : Asia/Amman
378 TimeZone ID : Asia/Beirut
379 TimeZone ID : Asia/Damascus
380 TimeZone ID : Asia/Gaza
381 TimeZone ID : Asia/Hebron
382 TimeZone ID : Asia/Istanbul
383 TimeZone ID : Asia/Jerusalem
384 TimeZone ID : Asia/Nicosia
385 TimeZone ID : Asia/Tel_Aviv
386 TimeZone ID : CAT
387 TimeZone ID : EET
388 TimeZone ID : Egypt
389 TimeZone ID : Etc/GMT-2
390 TimeZone ID : Europe/Athens
391 TimeZone ID : Europe/Bucharest
392 TimeZone ID : Europe/Chisinau
393 TimeZone ID : Europe/Helsinki
394 TimeZone ID : Europe/Istanbul
395 TimeZone ID : Europe/Kiev
396 TimeZone ID : Europe/Mariehamn
397 TimeZone ID : Europe/Nicosia
398 TimeZone ID : Europe/Riga
399 TimeZone ID : Europe/Simferopol
400 TimeZone ID : Europe/Sofia
401 TimeZone ID : Europe/Tallinn
402 TimeZone ID : Europe/Tiraspol
403 TimeZone ID : Europe/Uzhgorod
404 TimeZone ID : Europe/Vilnius
405 TimeZone ID : Europe/Zaporozhye
406 TimeZone ID : Israel
407 TimeZone ID : Libya
408 TimeZone ID : Turkey
409 TimeZone ID : Africa/Addis_Ababa
410 TimeZone ID : Africa/Asmara
411 TimeZone ID : Africa/Asmera
412 TimeZone ID : Africa/Dar_es_Salaam
413 TimeZone ID : Africa/Djibouti
414 TimeZone ID : Africa/Juba
415 TimeZone ID : Africa/Kampala
416 TimeZone ID : Africa/Khartoum
417 TimeZone ID : Africa/Mogadishu
418 TimeZone ID : Africa/Nairobi
419 TimeZone ID : Antarctica/Syowa
420 TimeZone ID : Asia/Aden
421 TimeZone ID : Asia/Baghdad
422 TimeZone ID : Asia/Bahrain
423 TimeZone ID : Asia/Kuwait
424 TimeZone ID : Asia/Qatar
425 TimeZone ID : Asia/Riyadh
426 TimeZone ID : EAT
427 TimeZone ID : Etc/GMT-3
428 TimeZone ID : Europe/Kaliningrad
429 TimeZone ID : Europe/Minsk
430 TimeZone ID : Indian/Antananarivo
431 TimeZone ID : Indian/Comoro
432 TimeZone ID : Indian/Mayotte
433 TimeZone ID : Asia/Riyadh87
434 TimeZone ID : Asia/Riyadh88
435 TimeZone ID : Asia/Riyadh89
436 TimeZone ID : Mideast/Riyadh87
437 TimeZone ID : Mideast/Riyadh88
438 TimeZone ID : Mideast/Riyadh89
439 TimeZone ID : Asia/Tehran
440 TimeZone ID : Iran
441 TimeZone ID : Asia/Baku
442 TimeZone ID : Asia/Dubai
443 TimeZone ID : Asia/Muscat
444 TimeZone ID : Asia/Tbilisi
445 TimeZone ID : Asia/Yerevan
446 TimeZone ID : Etc/GMT-4
447 TimeZone ID : Europe/Moscow
448 TimeZone ID : Europe/Samara
449 TimeZone ID : Europe/Volgograd
450 TimeZone ID : Indian/Mahe
451 TimeZone ID : Indian/Mauritius
452 TimeZone ID : Indian/Reunion
453 TimeZone ID : NET
454 TimeZone ID : W-SU
455 TimeZone ID : Asia/Kabul
456 TimeZone ID : Antarctica/Mawson
457 TimeZone ID : Asia/Aqtau
458 TimeZone ID : Asia/Aqtobe
459 TimeZone ID : Asia/Ashgabat
460 TimeZone ID : Asia/Ashkhabad
461 TimeZone ID : Asia/Dushanbe
462 TimeZone ID : Asia/Karachi
463 TimeZone ID : Asia/Oral
464 TimeZone ID : Asia/Samarkand
465 TimeZone ID : Asia/Tashkent
466 TimeZone ID : Etc/GMT-5
467 TimeZone ID : Indian/Kerguelen
468 TimeZone ID : Indian/Maldives
469 TimeZone ID : PLT
470 TimeZone ID : Asia/Calcutta
471 TimeZone ID : Asia/Colombo
472 TimeZone ID : Asia/Kolkata
473 TimeZone ID : IST
474 TimeZone ID : Asia/Kathmandu
475 TimeZone ID : Asia/Katmandu
476 TimeZone ID : Antarctica/Vostok
477 TimeZone ID : Asia/Almaty
478 TimeZone ID : Asia/Bishkek
479 TimeZone ID : Asia/Dacca
480 TimeZone ID : Asia/Dhaka
481 TimeZone ID : Asia/Qyzylorda
482 TimeZone ID : Asia/Thimbu
483 TimeZone ID : Asia/Thimphu
484 TimeZone ID : Asia/Yekaterinburg
485 TimeZone ID : BST
486 TimeZone ID : Etc/GMT-6
487 TimeZone ID : Indian/Chagos
488 TimeZone ID : Asia/Rangoon
489 TimeZone ID : Indian/Cocos
490 TimeZone ID : Antarctica/Davis
491 TimeZone ID : Asia/Bangkok
492 TimeZone ID : Asia/Ho_Chi_Minh
493 TimeZone ID : Asia/Hovd
494 TimeZone ID : Asia/Jakarta
495 TimeZone ID : Asia/Novokuznetsk
496 TimeZone ID : Asia/Novosibirsk
497 TimeZone ID : Asia/Omsk
498 TimeZone ID : Asia/Phnom_Penh
499 TimeZone ID : Asia/Pontianak
500 TimeZone ID : Asia/Saigon
501 TimeZone ID : Asia/Vientiane
502 TimeZone ID : Etc/GMT-7
503 TimeZone ID : Indian/Christmas
504 TimeZone ID : VST
505 TimeZone ID : Antarctica/Casey
506 TimeZone ID : Asia/Brunei
507 TimeZone ID : Asia/Choibalsan
508 TimeZone ID : Asia/Chongqing
509 TimeZone ID : Asia/Chungking
510 TimeZone ID : Asia/Harbin
511 TimeZone ID : Asia/Hong_Kong
512 TimeZone ID : Asia/Kashgar
513 TimeZone ID : Asia/Krasnoyarsk
514 TimeZone ID : Asia/Kuala_Lumpur
515 TimeZone ID : Asia/Kuching
516 TimeZone ID : Asia/Macao
517 TimeZone ID : Asia/Macau
518 TimeZone ID : Asia/Makassar
519 TimeZone ID : Asia/Manila
520 TimeZone ID : Asia/Shanghai
521 TimeZone ID : Asia/Singapore
522 TimeZone ID : Asia/Taipei
523 TimeZone ID : Asia/Ujung_Pandang
524 TimeZone ID : Asia/Ulaanbaatar
525 TimeZone ID : Asia/Ulan_Bator
526 TimeZone ID : Asia/Urumqi
527 TimeZone ID : Australia/Perth
528 TimeZone ID : Australia/West
529 TimeZone ID : CTT
530 TimeZone ID : Etc/GMT-8
531 TimeZone ID : Hongkong
532 TimeZone ID : PRC
533 TimeZone ID : Singapore
534 TimeZone ID : Australia/Eucla
535 TimeZone ID : Asia/Dili
536 TimeZone ID : Asia/Irkutsk
537 TimeZone ID : Asia/Jayapura
538 TimeZone ID : Asia/Pyongyang
539 TimeZone ID : Asia/Seoul
540 TimeZone ID : Asia/Tokyo
541 TimeZone ID : Etc/GMT-9
542 TimeZone ID : JST
543 TimeZone ID : Japan
544 TimeZone ID : Pacific/Palau
545 TimeZone ID : ROK
546 TimeZone ID : ACT
547 TimeZone ID : Australia/Adelaide
548 TimeZone ID : Australia/Broken_Hill
549 TimeZone ID : Australia/Darwin
550 TimeZone ID : Australia/North
551 TimeZone ID : Australia/South
552 TimeZone ID : Australia/Yancowinna
553 TimeZone ID : AET
554 TimeZone ID : Antarctica/DumontDUrville
555 TimeZone ID : Asia/Yakutsk
556 TimeZone ID : Australia/ACT
557 TimeZone ID : Australia/Brisbane
558 TimeZone ID : Australia/Canberra
559 TimeZone ID : Australia/Currie
560 TimeZone ID : Australia/Hobart
561 TimeZone ID : Australia/Lindeman
562 TimeZone ID : Australia/Melbourne
563 TimeZone ID : Australia/NSW
564 TimeZone ID : Australia/Queensland
565 TimeZone ID : Australia/Sydney
566 TimeZone ID : Australia/Tasmania
567 TimeZone ID : Australia/Victoria
568 TimeZone ID : Etc/GMT-10
569 TimeZone ID : Pacific/Chuuk
570 TimeZone ID : Pacific/Guam
571 TimeZone ID : Pacific/Port_Moresby
572 TimeZone ID : Pacific/Saipan
573 TimeZone ID : Pacific/Truk
574 TimeZone ID : Pacific/Yap
575 TimeZone ID : Australia/LHI
576 TimeZone ID : Australia/Lord_Howe
577 TimeZone ID : Antarctica/Macquarie
578 TimeZone ID : Asia/Sakhalin
579 TimeZone ID : Asia/Vladivostok
580 TimeZone ID : Etc/GMT-11
581 TimeZone ID : Pacific/Efate
582 TimeZone ID : Pacific/Guadalcanal
583 TimeZone ID : Pacific/Kosrae
584 TimeZone ID : Pacific/Noumea
585 TimeZone ID : Pacific/Pohnpei
586 TimeZone ID : Pacific/Ponape
587 TimeZone ID : SST
588 TimeZone ID : Pacific/Norfolk
589 TimeZone ID : Antarctica/McMurdo
590 TimeZone ID : Antarctica/South_Pole
591 TimeZone ID : Asia/Anadyr
592 TimeZone ID : Asia/Kamchatka
593 TimeZone ID : Asia/Magadan
594 TimeZone ID : Etc/GMT-12
595 TimeZone ID : Kwajalein
596 TimeZone ID : NST
597 TimeZone ID : NZ
598 TimeZone ID : Pacific/Auckland
599 TimeZone ID : Pacific/Fiji
600 TimeZone ID : Pacific/Funafuti
601 TimeZone ID : Pacific/Kwajalein
602 TimeZone ID : Pacific/Majuro
603 TimeZone ID : Pacific/Nauru
604 TimeZone ID : Pacific/Tarawa
605 TimeZone ID : Pacific/Wake
606 TimeZone ID : Pacific/Wallis
607 TimeZone ID : NZ-CHAT
608 TimeZone ID : Pacific/Chatham
609 TimeZone ID : Etc/GMT-13
610 TimeZone ID : MIT
611 TimeZone ID : Pacific/Apia
612 TimeZone ID : Pacific/Enderbury
613 TimeZone ID : Pacific/Fakaofo
614 TimeZone ID : Pacific/Tongatapu
615 TimeZone ID : Etc/GMT-14
616 TimeZone ID : Pacific/Kiritimati




F. Add Months to Calendar in Java


Date_Ex6.java

import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.GregorianCalendar;
import java.util.Scanner;
 
public class Date_Ex6 {
	
	Calendar calendar = new GregorianCalendar(1991,Calendar.OCTOBER,7);
	SimpleDateFormat formatter = new SimpleDateFormat("dd-MMMM-yyyy");
	Scanner scan = new Scanner(System.in);
	
	void getDate() {
		
		System.out.println("Add Month");
		
		String date = formatter.format(calendar.getTime());
		System.out.println("\nDate : " + date);
	}
	
	void add() {
		
		System.out.println("How many months to add :");
		int month = scan.nextInt();
 
		calendar.add(Calendar.MONTH, month);
		String date = formatter.format(calendar.getTime());
 
		System.out.println("\nAfter " + month  + " months : " + date);
	}
}
 
class MainClass {
	
	public static void main(String args[]) {
		
		Date_Ex6 obj = new Date_Ex6();
		
		obj.getDate();
		obj.add();
	}
}

Sample Output

Add Month

Date : 07-October-1991
How many months to add :
11

After 11 months : 07-September-1992




G. Subtract Months to Calendar in Java


Date_Ex7.java

import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.GregorianCalendar;
import java.util.Scanner;
 
public class Date_Ex7 {
	
	Calendar calendar = new GregorianCalendar(1991,Calendar.OCTOBER,7);
	SimpleDateFormat formatter = new SimpleDateFormat("dd-MMMM-yyyy");
	Scanner scan = new Scanner(System.in);
	
	void getDate() {
		
		System.out.println("Subtract Month");
		
		String date = formatter.format(calendar.getTime());
		System.out.println("\nDate : " + date);
	}
	
	void add() {
		
		System.out.println("How many months to subtract :");
		int month = scan.nextInt();
 
		calendar.add(Calendar.MONTH, -month);
		String date = formatter.format(calendar.getTime());
 
		System.out.println("\nBefore " + month  + " months : " + date);
	}
}
 
class MainClass {
	
	public static void main(String args[]) {
		
		Date_Ex7 obj = new Date_Ex7();
		
		obj.getDate();
		obj.add();
	}
}

Sample Output

Subtract Month

Date : 07-October-1991
How many months to subtract :
10

Before 10 months : 07-December-1990




H. Add Day, Month & Year to Calendar in Java


Date_Ex8.java

import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.GregorianCalendar;
import java.util.Scanner;
 
public class Date_Ex8 {
	
	Calendar calendar = new GregorianCalendar(1991,Calendar.OCTOBER,7);
	SimpleDateFormat formatter = new SimpleDateFormat("dd-MMMM-yyyy");
	Scanner scan = new Scanner(System.in);
	
	void getDate() {
		
		System.out.println("Add Day, Month, Year");
		
		String date = formatter.format(calendar.getTime());
		System.out.println("\nDate : " + date);
	}
	
	void addDay() {
		
		System.out.println("\nHow many days to Add :");
		int day = scan.nextInt();
 
		calendar.add(Calendar.DAY_OF_YEAR, day);
		
		String date = formatter.format(calendar.getTime());
 
		System.out.println("After " + day  + " days : " + date);
	}
	
	void addMonth() {
		
		System.out.println("\nHow many months to Add :");
		int month = scan.nextInt();
 
		calendar.add(Calendar.MONTH, month);
		
		String date = formatter.format(calendar.getTime());
 
		System.out.println("After " + month  + " months : " + date);
	}
	
	void addYear() {
		
		System.out.println("\nHow many years to Add :");
		int year = scan.nextInt();
 
		calendar.add(Calendar.YEAR, year);
		
		String date = formatter.format(calendar.getTime());
 
		System.out.println("After " + year  + " years : " + date);
	}
}
 
class MainClass {
	
	public static void main(String args[]) {
		
		Date_Ex8 obj = new Date_Ex8();
		
		obj.getDate();
		obj.addDay();
		obj.addMonth();
		obj.addYear();
	}
}

Sample Output

Add Day, Month, Year

Date : 07-October-1991

How many days to Add :
4
After 4 days : 11-October-1991

How many months to Add :
3
After 3 months : 11-January-1992

How many years to Add :
10
After 10 years : 11-January-2002






SHARE THIS PAGE



product 2

product 3

Feedbacks : balaji.scz@gmail.com