0

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.

Kristiono Setyadi
  • 5,635
  • 1
  • 19
  • 29
raghumudem
  • 747
  • 1
  • 9
  • 17

1 Answers1

2
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 .

Nikhil
  • 1,212
  • 13
  • 30
amal
  • 1,369
  • 8
  • 15
  • The above code working for me for some of date but it is nit working to show the current date of los angeles. It is showing wrong by adding 5.30 hours of time. how can i get the current time now? – raghumudem Aug 08 '11 at 05:54