Reputation: 797
Hi i developing a application in android. i need to use the Los Angeles (USA) location current time, date. For that I used the below code
Calendar calendar = Calendar.getInstance();
TimeZone tz = TimeZone.getTimeZone("America/Los_Angeles");
calendar.setTimeZone(tz);
String s=calendar.getTime().toString();
But it is giving the current location time and date. Please provide a code to get the time and date by providing particular location name like Los Angeles.
Upvotes: 0
Views: 2053
Reputation: 1369
Calendar calendar = Calendar.getInstance();
SimpleDateFormat sdf = new SimpleDateFormat("dd-MMM-yyyy hh:mm:ss z");
sdf.setTimeZone(TimeZone.getTimeZone("America/Los_Angeles"));
System.out.println(sdf.format(calendar.getTime()));
FYI, a Date is nothing more than a specific instant in time .
Upvotes: 2