-5

My Input will be timezone

String timeZone = currentTimeZone.getID();
timezone = America/Los_Angeles

Out put should be the day belongs to that timezone .

Monday

Here is what I have tried so far.

SimpleDateFormat sdf = new SimpleDateFormat("dd-MM-yyyy hh:mm:ss"); 
Date datetime = new Date(); 
sdf.setTimeZone(TimeZone.getTimeZone("Asia/Calcutta")); 
System.out.println("Asia/Calcutta "+ sdf.format(datetime));
Gunaseelan
  • 2,494
  • 5
  • 36
  • 43
Meenu
  • 11
  • 5

3 Answers3

1
Calendar calendar = Calendar.getInstance();
Calendar LATime = new GregorianCalendar(TimeZone.getTimeZone("America/Los_Angeles"));
LATime.setTimeInMillis(calendar.getTimeInMillis());
int year = LATime.get(Calendar.YEAR);
int month = LATime.get(Calendar.MONTH);
int date = LATime.get(Calendar.DATE);
int dayOfWeek = calender.get(Calendar.DAY_OF_WEEK);

Try it out

Boola
  • 358
  • 3
  • 14
0

You can use other answer which gives you an integer and then you can map that to Day of Week accordingly or you can use SimpleDateFormat to print Day of Week like this:

SimpleDateFormat sdf = new SimpleDateFormat("EEEE");
Date datetime = new Date();
sdf.setTimeZone(TimeZone.getTimeZone("America/Los_Angeles"));
System.out.println("America/Los_Angeles " + sdf.format(datetime));

Hope this helps.

Sanjeev
  • 9,876
  • 2
  • 22
  • 33
0
>  String[] days =
>                 {"Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"};
>         Calendar calendar = Calendar.getInstance();
>         Calendar LATime = new GregorianCalendar(TimeZone.getTimeZone("America/Los_Angeles"));
>         LATime.setTimeInMillis(calendar.getTimeInMillis());
>         int year = LATime.get(Calendar.YEAR);
>         int month = LATime.get(Calendar.MONTH);
>         int date = LATime.get(Calendar.DATE);
>         int dayOfWeek = calendar.get(Calendar.DAY_OF_WEEK);
>         System.out.println(days[dayOfWeek -1]);

Also we can set the calendar.setFirstDayOfWeek(); default it is sunday the starting of the week.

Kgn
  • 231
  • 3
  • 14