android - How to get the weekday of a Date? -


i want day of week java date object when have array of date in string me.

simpledateformat  sourcedateformat = new simpledateformat("yyyy-mm-dd"); public string[] temp_date; public int[] day = new int[5]; date[] d1= new date[5]; calendar[] cal= new calendar[5]    try {      d1[i]= sourcedateformat.parse(temp_date[i].tostring());      cal[i].settime(d1[i]);   // not compiling line..showing error on line      day[i]= cal[i].get(calendar.day_of_week);           }   catch (parseexception e) {         e.printstacktrace();     } 

does know answer this?

you can day-integer that:

calendar c = calendar.getinstance(); c.settime(yourdate); // yourdate object of type date  int dayofweek = c.get(calendar.day_of_week); // example return 2 tuesday 

if need output "tue" rather 2, instead of going through calendar, reformat string: new simpledateformat("ee").format(date) (ee meaning "day of week, short version")

taken here: how determine day of week passing specific date?


Comments

Popular posts from this blog

html - How to style widget with post count different than without post count -

How to remove text and logo OR add Overflow on Android ActionBar using AppCompat on API 8? -

javascript - storing input from prompt in array and displaying the array -