How can I get the current time programmatically in android in Los Angeles (USA)?

Hi, I am developing an application in android. I need to use the current time, date in Los Angeles (USA). For this, I used the code below

Calendar calendar = Calendar.getInstance(); TimeZone tz = TimeZone.getTimeZone("America/Los_Angeles"); calendar.setTimeZone(tz); String s=calendar.getTime().toString(); 

But it indicates the current location and date. Please provide the code to find out the time and date, indicating the exact name of the location, for example, Los Angeles.

0
android
source share
1 answer
  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 point in time.

+2
source share

All Articles