Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get day from specified date in android

Suppose my date is 02-01-2013

and it is stored in a variable like:

String strDate = "02-01-2013";

then how should I get the day of this date (i.e TUESDAY)?

like image 334
Android is everything for me Avatar asked Dec 12 '22 19:12

Android is everything for me


1 Answers

Use Calendar class from java api.

Calendar calendar = new GregorianCalendar(2008, 01, 01); // Note that Month value is 0-based. e.g., 0 for January.
int reslut = calendar.get(Calendar.DAY_OF_WEEK);
switch (result) {
case Calendar.MONDAY:
    System.out.println("It's Monday !");
    break;
}

You could also use SimpleDateFormater and Date for parsing dates

Date date = new Date();
SimpleDateFormat date_format = new SimpleDateFormat("yyyy-MM-dd");
try {
    date = date_format.parse("2008-01-01");
} catch (ParseException e) {
    e.printStackTrace();
}

calendar.setTime(date);
like image 67
jellyfication Avatar answered Dec 24 '22 01:12

jellyfication