Skip to content Skip to sidebar Skip to footer

How The Get The Current Day Name Using Particular Date In Android?

I have date string 18-2-2012 , from this how to get the current day name i.e., today is 'saturday' like this. for tomorrow's date 19-2-2012 and the day name is 'sunday'.

Solution 1:

Use java date formats.

SimpleDateFormatinFormat=newSimpleDateFormat("dd-MM-yyyy");
Datedate= inFormat.parse(input);
SimpleDateFormatoutFormat=newSimpleDateFormat("EEEE");
Stringgoal= outFormat.format(date); 

Solution 2:

You can use Calendar

Calendar calendar = Calendar.getInstance();

            calendar.setTime(date_your_want_to_know);

            String[] days = newString[] { "SUNDAY", "MONDAY", "TUESDAY", "WEDNESDAY", "THURSDAY", "FRIDAY", "SATURDAY" }

            String day = days[calendar.get(Calendar.DAY_OF_WEEK)];

Solution 3:

Just use a single line of code:

android.text.format.DateFormat.format("EEEE", date);

Solution 4:

int dayOfWeek=bday.get(Calendar.DAY_OF_WEEK);  // Returns 3, for Tuesday!

for more detail go here.... http://mobile.tutsplus.com/tutorials/android/java_android_date-and-time/

Solution 5:

First convert the date string to a Date using SimpleDateFormat.

Then make a Calendar instance from that date.

Finally, retrieve the day of week from the Calendar using the get(Calendar.DAY_OF_WEEK). This will give you an integer between 1 to 7 representing the day of the week. You can simple map this to an array of Strings to get the days.

Post a Comment for "How The Get The Current Day Name Using Particular Date In Android?"