[Last Call] Learn how to a build a cloud-first strategyRegister Now

x
Solved

# Date and Time in Different Places

Posted on 2001-07-27
Medium Priority
2,280 Views
I've an application in which a Specfic User wants to login all his team mates,those r in different countries,Login a specfic Time for Eg:.Suppose he specifies his time as 10AM of Indian Time...I want to convert this time,for eg: an US user or a French User,according to their Countries time..ie an US user must see the time like 8PM
<p>Can anybody help me on this.... Example codes will more helpfull to me......Thanks in Advance.....
0
Question by:sujeeshlal

LVL 3

Expert Comment

ID: 6325830
get the TimeZone by:
TimeZone tz = TimeZone.getTimeZone("America/Los_Angeles");
then crate a calendar for that timezone and locale
Calendar cal = Calendar(tz, Locale.US);
0

LVL 9

Expert Comment

ID: 6325909
>> Calendar cal = Calendar(tz, Locale.US);

How do you instantiate an abstract class?
0

Expert Comment

ID: 6325925
Try to use that code

TimeZone tz = TimeZone.getTimeZone("America/Los_Angeles");
Date d = Calendar.getInstance(tz, Locale.US).getTime();
0

Author Comment

ID: 6325948
But I think
Date d = Calendar.getInstance(tz, Locale.US).getTime()
will creates a Locale object for the United States Only...I want to create a Locale object of that place which ever be that country,may be that is UK,Singapore..etc..Is there any solutions?...
0

Author Comment

ID: 6325956
But I think
Date d = Calendar.getInstance(tz, Locale.US).getTime()
will creates a Locale object for the United States Only...I want to create a Locale object of that place which ever be that country,may be that is UK,Singapore..etc..Is there any solutions?...
0

LVL 9

Accepted Solution

yongsing earned 300 total points
ID: 6325979
TimeZone timeZone = TimeZone.getTimeZone("America/Los_Angeles");
GregorianCalendar calendar = new GregorianCalendar(timeZone, Locale.US);

int year = calendar.get(Calendar.YEAR);
int month = calendar.get(Calendar.MONTH) + 1;
int day = calendar.get(Calendar.DAY_OF_MONTH);
int hour = calendar.get(Calendar.HOUR);
int minute = calendar.get(Calendar.MINUTE);
int second = calendar.get(Calendar.SECOND);

System.out.println(year + "-" + month + "-" + day + ", " + hour + ":" + minute + ":" + second);
0

LVL 9

Expert Comment

ID: 6326017
For Singapore:
TimeZone timeZone = TimeZone.getTimeZone("Asia/Singapore");

For London:
TimeZone timeZone = TimeZone.getTimeZone("Europe/London");

Or, if you want the current time in every country, try this:

String[] ids = TimeZone.getAvailableIDs();
for (int i = 0; i < ids.length; i++) {
TimeZone timeZone = TimeZone.getTimeZone(ids[i]);
GregorianCalendar calendar = new GregorianCalendar(timeZone, Locale.US);
int year = calendar.get(Calendar.YEAR);
int month = calendar.get(Calendar.MONTH) + 1;
int day = calendar.get(Calendar.DAY_OF_MONTH);
int hour = calendar.get(Calendar.HOUR);
int minute = calendar.get(Calendar.MINUTE);
int second = calendar.get(Calendar.SECOND);
String am_pm = (calendar.get(Calendar.AM_PM) == Calendar.AM) ? "am" : "pm";
System.out.println(ids[i] + ": " + year + "-" + month + "-" + day + ", " + hour + ":" + minute + ":" + second + am_pm);
}

This is the result:

Pacific/Niue: 2001-7-26, 9:26:25pm
Pacific/Apia: 2001-7-26, 9:26:25pm
MIT: 2001-7-26, 9:26:25pm
Pacific/Pago_Pago: 2001-7-26, 9:26:25pm
Pacific/Tahiti: 2001-7-26, 10:26:25pm
Pacific/Fakaofo: 2001-7-26, 10:26:25pm
Pacific/Honolulu: 2001-7-26, 10:26:25pm
HST: 2001-7-26, 10:26:25pm
Pacific/Rarotonga: 2001-7-26, 10:26:25pm
Pacific/Marquesas: 2001-7-26, 10:56:25pm
Pacific/Gambier: 2001-7-26, 11:26:25pm
America/Anchorage: 2001-7-27, 0:26:25am
AST: 2001-7-27, 0:26:25am
Pacific/Pitcairn: 2001-7-26, 11:56:25pm
America/Vancouver: 2001-7-27, 1:26:25am
America/Tijuana: 2001-7-27, 1:26:25am
America/Los_Angeles: 2001-7-27, 1:26:25am
PST: 2001-7-27, 1:26:25am
America/Dawson_Creek: 2001-7-27, 1:26:25am
America/Phoenix: 2001-7-27, 1:26:25am
PNT: 2001-7-27, 1:26:25am
America/Edmonton: 2001-7-27, 2:26:25am
America/Mazatlan: 2001-7-27, 2:26:25am
America/Denver: 2001-7-27, 2:26:25am
MST: 2001-7-27, 2:26:25am
America/Belize: 2001-7-27, 2:26:25am
America/Regina: 2001-7-27, 2:26:25am
Pacific/Galapagos: 2001-7-27, 2:26:25am
America/Guatemala: 2001-7-27, 2:26:25am
America/Tegucigalpa: 2001-7-27, 2:26:25am
America/Costa_Rica: 2001-7-27, 2:26:25am
America/Winnipeg: 2001-7-27, 3:26:25am
Pacific/Easter: 2001-7-27, 2:26:25am
America/Mexico_City: 2001-7-27, 3:26:25am
America/Chicago: 2001-7-27, 3:26:25am
CST: 2001-7-27, 3:26:25am
America/Porto_Acre: 2001-7-27, 3:26:25am
America/Bogota: 2001-7-27, 3:26:25am
America/Guayaquil: 2001-7-27, 3:26:25am
America/Jamaica: 2001-7-27, 3:26:25am
America/Cayman: 2001-7-27, 3:26:25am
America/Managua: 2001-7-27, 3:26:25am
America/Panama: 2001-7-27, 3:26:25am
America/Lima: 2001-7-27, 3:26:25am
America/Indianapolis: 2001-7-27, 3:26:25am
IET: 2001-7-27, 3:26:25am
America/Nassau: 2001-7-27, 4:26:25am
America/Montreal: 2001-7-27, 4:26:25am
America/Havana: 2001-7-27, 4:26:25am
America/Port-au-Prince: 2001-7-27, 3:26:25am
America/Grand_Turk: 2001-7-27, 4:26:25am
America/New_York: 2001-7-27, 4:26:25am
EST: 2001-7-27, 4:26:25am
America/Antigua: 2001-7-27, 4:26:25am
America/Anguilla: 2001-7-27, 4:26:25am
America/Curacao: 2001-7-27, 4:26:25am
America/Aruba: 2001-7-27, 4:26:25am
America/La_Paz: 2001-7-27, 4:26:25am
America/Manaus: 2001-7-27, 4:26:25am
America/Dominica: 2001-7-27, 4:26:25am
America/Santo_Domingo: 2001-7-27, 4:26:25am
America/Guyana: 2001-7-27, 4:26:25am
America/St_Kitts: 2001-7-27, 4:26:25am
America/St_Lucia: 2001-7-27, 4:26:25am
America/Martinique: 2001-7-27, 4:26:25am
America/Montserrat: 2001-7-27, 4:26:25am
America/Puerto_Rico: 2001-7-27, 4:26:25am
PRT: 2001-7-27, 4:26:25am
America/Port_of_Spain: 2001-7-27, 4:26:25am
America/St_Vincent: 2001-7-27, 4:26:25am
America/Tortola: 2001-7-27, 4:26:25am
America/St_Thomas: 2001-7-27, 4:26:25am
America/Caracas: 2001-7-27, 4:26:25am
Antarctica/Palmer: 2001-7-27, 4:26:25am
Atlantic/Bermuda: 2001-7-27, 5:26:25am
America/Cuiaba: 2001-7-27, 4:26:25am
America/Halifax: 2001-7-27, 5:26:25am
Atlantic/Stanley: 2001-7-27, 4:26:25am
America/Thule: 2001-7-27, 5:26:25am
America/Asuncion: 2001-7-27, 4:26:25am
America/Santiago: 2001-7-27, 4:26:25am
America/St_Johns: 2001-7-27, 5:56:25am
CNT: 2001-7-27, 5:56:25am
America/Fortaleza: 2001-7-27, 5:26:25am
America/Cayenne: 2001-7-27, 5:26:25am
America/Paramaribo: 2001-7-27, 5:26:25am
America/Montevideo: 2001-7-27, 5:26:25am
America/Buenos_Aires: 2001-7-27, 5:26:25am
AGT: 2001-7-27, 5:26:25am
America/Godthab: 2001-7-27, 6:26:25am
America/Miquelon: 2001-7-27, 6:26:25am
America/Sao_Paulo: 2001-7-27, 5:26:25am
BET: 2001-7-27, 5:26:25am
America/Noronha: 2001-7-27, 6:26:25am
Atlantic/South_Georgia: 2001-7-27, 6:26:25am
Atlantic/Jan_Mayen: 2001-7-27, 7:26:25am
Atlantic/Cape_Verde: 2001-7-27, 7:26:25am
America/Scoresbysund: 2001-7-27, 8:26:25am
Atlantic/Azores: 2001-7-27, 8:26:25am
Africa/Abidjan: 2001-7-27, 8:26:25am
Africa/Accra: 2001-7-27, 8:26:25am
Africa/Banjul: 2001-7-27, 8:26:25am
Africa/Conakry: 2001-7-27, 8:26:25am
Africa/Bissau: 2001-7-27, 8:26:25am
Atlantic/Reykjavik: 2001-7-27, 8:26:25am
Africa/Monrovia: 2001-7-27, 8:26:25am
Africa/Casablanca: 2001-7-27, 8:26:25am
Africa/Timbuktu: 2001-7-27, 8:26:25am
Africa/Nouakchott: 2001-7-27, 8:26:25am
Atlantic/St_Helena: 2001-7-27, 8:26:25am
Africa/Freetown: 2001-7-27, 8:26:25am
Africa/Dakar: 2001-7-27, 8:26:25am
Africa/Sao_Tome: 2001-7-27, 8:26:25am
Africa/Lome: 2001-7-27, 8:26:25am
GMT: 2001-7-27, 8:26:25am
UTC: 2001-7-27, 8:26:25am
Atlantic/Faeroe: 2001-7-27, 9:26:25am
Atlantic/Canary: 2001-7-27, 9:26:25am
Europe/Dublin: 2001-7-27, 9:26:25am
Europe/Lisbon: 2001-7-27, 9:26:25am
Europe/London: 2001-7-27, 9:26:25am
Africa/Luanda: 2001-7-27, 9:26:25am
Africa/Porto-Novo: 2001-7-27, 9:26:25am
Africa/Bangui: 2001-7-27, 9:26:25am
Africa/Kinshasa: 2001-7-27, 9:26:25am
Africa/Douala: 2001-7-27, 9:26:25am
Africa/Libreville: 2001-7-27, 9:26:25am
Africa/Malabo: 2001-7-27, 9:26:25am
Africa/Niamey: 2001-7-27, 9:26:25am
Africa/Lagos: 2001-7-27, 9:26:25am
Africa/Ndjamena: 2001-7-27, 9:26:25am
Africa/Tunis: 2001-7-27, 9:26:25am
Africa/Algiers: 2001-7-27, 9:26:25am
Europe/Andorra: 2001-7-27, 10:26:25am
Europe/Tirane: 2001-7-27, 10:26:25am
Europe/Vienna: 2001-7-27, 10:26:25am
Europe/Brussels: 2001-7-27, 10:26:25am
Europe/Zurich: 2001-7-27, 10:26:25am
Europe/Prague: 2001-7-27, 10:26:25am
Europe/Berlin: 2001-7-27, 10:26:25am
Europe/Copenhagen: 2001-7-27, 10:26:25am
Europe/Gibraltar: 2001-7-27, 10:26:25am
Europe/Budapest: 2001-7-27, 10:26:25am
Europe/Rome: 2001-7-27, 10:26:25am
Europe/Luxembourg: 2001-7-27, 10:26:25am
Africa/Tripoli: 2001-7-27, 10:26:25am
Europe/Monaco: 2001-7-27, 10:26:25am
Europe/Malta: 2001-7-27, 10:26:25am
Africa/Windhoek: 2001-7-27, 9:26:25am
Europe/Amsterdam: 2001-7-27, 10:26:25am
Europe/Oslo: 2001-7-27, 10:26:25am
Europe/Warsaw: 2001-7-27, 10:26:25am
Europe/Stockholm: 2001-7-27, 10:26:25am
Europe/Paris: 2001-7-27, 10:26:25am
ECT: 2001-7-27, 10:26:25am
Africa/Bujumbura: 2001-7-27, 10:26:25am
Africa/Gaborone: 2001-7-27, 10:26:25am
Africa/Lubumbashi: 2001-7-27, 10:26:25am
Africa/Maseru: 2001-7-27, 10:26:25am
Africa/Blantyre: 2001-7-27, 10:26:25am
Africa/Maputo: 2001-7-27, 10:26:25am
Africa/Kigali: 2001-7-27, 10:26:25am
Africa/Khartoum: 2001-7-27, 10:26:25am
Africa/Mbabane: 2001-7-27, 10:26:25am
Africa/Lusaka: 2001-7-27, 10:26:25am
Africa/Harare: 2001-7-27, 10:26:25am
CAT: 2001-7-27, 10:26:25am
Africa/Johannesburg: 2001-7-27, 10:26:25am
Europe/Sofia: 2001-7-27, 11:26:25am
Europe/Minsk: 2001-7-27, 11:26:25am
Asia/Nicosia: 2001-7-27, 11:26:25am
Europe/Tallinn: 2001-7-27, 11:26:25am
Africa/Cairo: 2001-7-27, 11:26:25am
ART: 2001-7-27, 11:26:25am
Europe/Helsinki: 2001-7-27, 11:26:25am
Europe/Athens: 2001-7-27, 11:26:25am
Asia/Jerusalem: 2001-7-27, 11:26:25am
Asia/Amman: 2001-7-27, 10:26:25am
Asia/Beirut: 2001-7-27, 11:26:25am
Europe/Vilnius: 2001-7-27, 10:26:25am
Europe/Riga: 2001-7-27, 11:26:25am
Europe/Chisinau: 2001-7-27, 11:26:25am
Europe/Bucharest: 2001-7-27, 11:26:25am
Asia/Damascus: 2001-7-27, 11:26:25am
Europe/Kiev: 2001-7-27, 11:26:25am
Europe/Istanbul: 2001-7-27, 11:26:25am
EET: 2001-7-27, 11:26:25am
Asia/Bahrain: 2001-7-27, 11:26:25am
Africa/Djibouti: 2001-7-27, 11:26:25am
Africa/Asmera: 2001-7-27, 11:26:25am
EAT: 2001-7-27, 11:26:25am
Africa/Nairobi: 2001-7-27, 11:26:25am
Indian/Comoro: 2001-7-27, 11:26:25am
Asia/Kuwait: 2001-7-27, 11:26:25am
Indian/Antananarivo: 2001-7-27, 11:26:25am
Asia/Qatar: 2001-7-27, 11:26:25am
Africa/Dar_es_Salaam: 2001-7-27, 11:26:25am
Africa/Kampala: 2001-7-27, 11:26:25am
Indian/Mayotte: 2001-7-27, 11:26:25am
Europe/Simferopol: 2001-7-27, 11:26:25am
Europe/Moscow: 2001-7-27, 0:26:25pm
Asia/Tehran: 2001-7-27, 0:56:25pm
MET: 2001-7-27, 0:56:25pm
Asia/Dubai: 2001-7-27, 0:26:25pm
Indian/Mauritius: 2001-7-27, 0:26:25pm
Asia/Muscat: 2001-7-27, 0:26:25pm
Indian/Reunion: 2001-7-27, 0:26:25pm
Indian/Mahe: 2001-7-27, 0:26:25pm
Asia/Yerevan: 2001-7-27, 1:26:25pm
NET: 2001-7-27, 1:26:25pm
Asia/Baku: 2001-7-27, 1:26:25pm
Asia/Aqtau: 2001-7-27, 1:26:25pm
Europe/Samara: 2001-7-27, 1:26:25pm
Asia/Kabul: 2001-7-27, 0:56:25pm
Indian/Kerguelen: 2001-7-27, 1:26:25pm
Asia/Tbilisi: 2001-7-27, 1:26:25pm
Indian/Chagos: 2001-7-27, 1:26:25pm
Indian/Maldives: 2001-7-27, 1:26:25pm
Asia/Dushanbe: 2001-7-27, 1:26:25pm
Asia/Tashkent: 2001-7-27, 1:26:25pm
Asia/Karachi: 2001-7-27, 1:26:25pm
PLT: 2001-7-27, 1:26:25pm
Asia/Bishkek: 2001-7-27, 2:26:25pm
Asia/Aqtobe: 2001-7-27, 2:26:25pm
Asia/Yekaterinburg: 2001-7-27, 2:26:25pm
Asia/Calcutta: 2001-7-27, 1:56:25pm
IST: 2001-7-27, 1:56:25pm
Asia/Katmandu: 2001-7-27, 2:11:25pm
Antarctica/Mawson: 2001-7-27, 2:26:25pm
Asia/Thimbu: 2001-7-27, 2:26:25pm
Asia/Colombo: 2001-7-27, 2:26:25pm
Asia/Dacca: 2001-7-27, 2:26:25pm
BST: 2001-7-27, 2:26:25pm
Asia/Almaty: 2001-7-27, 3:26:25pm
Asia/Novosibirsk: 2001-7-27, 3:26:25pm
Indian/Cocos: 2001-7-27, 2:56:25pm
Asia/Rangoon: 2001-7-27, 2:56:25pm
Indian/Christmas: 2001-7-27, 3:26:25pm
Asia/Jakarta: 2001-7-27, 3:26:25pm
Asia/Phnom_Penh: 2001-7-27, 3:26:25pm
Asia/Vientiane: 2001-7-27, 3:26:25pm
Asia/Saigon: 2001-7-27, 3:26:25pm
VST: 2001-7-27, 3:26:25pm
Asia/Bangkok: 2001-7-27, 3:26:25pm
Asia/Krasnoyarsk: 2001-7-27, 4:26:25pm
Antarctica/Casey: 2001-7-27, 4:26:25pm
Australia/Perth: 2001-7-27, 4:26:25pm
Asia/Brunei: 2001-7-27, 4:26:25pm
Asia/Hong_Kong: 2001-7-27, 4:26:25pm
Asia/Ujung_Pandang: 2001-7-27, 4:26:25pm
Asia/Macao: 2001-7-27, 4:26:25pm
Asia/Kuala_Lumpur: 2001-7-27, 4:26:25pm
Asia/Manila: 2001-7-27, 4:26:25pm
Asia/Singapore: 2001-7-27, 4:26:25pm
Asia/Taipei: 2001-7-27, 4:26:25pm
Asia/Shanghai: 2001-7-27, 4:26:25pm
CTT: 2001-7-27, 4:26:25pm
Asia/Ulan_Bator: 2001-7-27, 5:26:25pm
Asia/Irkutsk: 2001-7-27, 5:26:25pm
Asia/Jayapura: 2001-7-27, 5:26:25pm
Asia/Pyongyang: 2001-7-27, 5:26:25pm
Asia/Seoul: 2001-7-27, 5:26:25pm
Pacific/Palau: 2001-7-27, 5:26:25pm
Asia/Tokyo: 2001-7-27, 5:26:25pm
JST: 2001-7-27, 5:26:25pm
Asia/Yakutsk: 2001-7-27, 6:26:25pm
Australia/Darwin: 2001-7-27, 5:56:25pm
ACT: 2001-7-27, 5:56:25pm
Australia/Broken_Hill: 2001-7-27, 5:56:25pm
Australia/Hobart: 2001-7-27, 6:26:25pm
Antarctica/DumontDUrville: 2001-7-27, 6:26:25pm
Pacific/Truk: 2001-7-27, 6:26:25pm
Pacific/Guam: 2001-7-27, 6:26:25pm
Pacific/Saipan: 2001-7-27, 6:26:25pm
Pacific/Port_Moresby: 2001-7-27, 6:26:25pm
Australia/Brisbane: 2001-7-27, 6:26:25pm
Australia/Sydney: 2001-7-27, 6:26:25pm
AET: 2001-7-27, 6:26:25pm
Australia/Lord_Howe: 2001-7-27, 6:56:25pm
Pacific/Ponape: 2001-7-27, 7:26:25pm
Pacific/Efate: 2001-7-27, 7:26:25pm
SST: 2001-7-27, 7:26:25pm
Pacific/Noumea: 2001-7-27, 7:26:25pm
Pacific/Norfolk: 2001-7-27, 7:56:25pm
Pacific/Kosrae: 2001-7-27, 8:26:25pm
Pacific/Tarawa: 2001-7-27, 8:26:25pm
Pacific/Majuro: 2001-7-27, 8:26:25pm
Pacific/Nauru: 2001-7-27, 8:26:25pm
Pacific/Funafuti: 2001-7-27, 8:26:25pm
Pacific/Wake: 2001-7-27, 8:26:25pm
Pacific/Wallis: 2001-7-27, 8:26:25pm
Pacific/Fiji: 2001-7-27, 8:26:25pm
Antarctica/McMurdo: 2001-7-27, 8:26:25pm
Asia/Kamchatka: 2001-7-27, 9:26:25pm
Pacific/Auckland: 2001-7-27, 8:26:25pm
NST: 2001-7-27, 8:26:25pm
Pacific/Chatham: 2001-7-27, 9:11:25pm
Pacific/Enderbury: 2001-7-27, 9:26:25pm
Pacific/Tongatapu: 2001-7-27, 9:26:25pm
Pacific/Kiritimati: 2001-7-27, 10:26:25pm
0

Author Comment

ID: 6326030
Thanx....For ur excellent reply and Make me clear abt my doubt..But let me ask u one more doubt regarding that..
here GregorianCalendar calendar = new GregorianCalendar(timeZone, Locale.US),is this is enough to get there local time whatever be the country...I mean if we make an object of calender as Locale.US ,Can he get the Current time of the country if he is in China or Singapore or in Africa...
0

LVL 9

Expert Comment

ID: 6329085
Yes, provided that the time and the time zone is set properly on his computer.
0

## Featured Post

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Java contains several comparison operators (e.g., <, <=, >, >=, ==, !=) that allow you to compare primitive values. However, these operators cannot be used to compare the contents of objects. Interface Comparable is used to allow objects of a clā¦
Introduction This article is the second of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article covers the basic installation and configuration of the test automation tools used byā¦
Viewers will learn about the regular for loop in Java and how to use it. Definition: Break the for loop down into 3 parts: Syntax when using for loops: Example using a for loop:
This video teaches viewers about errors in exception handling.
###### Suggested Courses
Course of the Month17 days, 14 hours left to enroll

#### 830 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.