Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android - format Date to "Day, Month dd, yyyy"

I get from the user, the date he sets in a DatePickerDialog. The date i get is in this format:

int selectedYear, int selectedMonth, int selectedDay

Can i format it to be like this "Day, Month dd, yyyy" as shown in the picture below?

enter image description here

like image 859
Christos Baziotis Avatar asked Nov 12 '13 12:11

Christos Baziotis


People also ask

How do you format a date?

Press CTRL+1. In the Format Cells box, click the Number tab. In the Category list, click Date, and then choose a date format you want in Type.

What is simple date format?

SimpleDateFormat is a concrete class for formatting and parsing dates in a locale-sensitive manner. It allows for formatting (date -> text), parsing (text -> date), and normalization. SimpleDateFormat allows you to start by choosing any user-defined patterns for date-time formatting.


2 Answers

Using the values returned from picker

    int selectedYear = 2013;
    int selectedDay = 20;
    int selectedMonth = 11;

    Calendar cal = Calendar.getInstance();
    cal.set(Calendar.YEAR, selectedYear);
    cal.set(Calendar.DAY_OF_MONTH, selectedDay);
    cal.set(Calendar.MONTH, selectedMonth);
    String format = new SimpleDateFormat("E, MMM d, yyyy").format(cal.getTime());
like image 103
dafi Avatar answered Oct 15 '22 04:10

dafi


You can Try This:

SimpleDateFormat sdf = new SimpleDateFormat("EEE-dd-MM-yyyy"); // Set your date format
String currentData = sdf.format(your actual date); // Get Date String according to date format

Here you can see details and all supported format:

http://developer.android.com/reference/java/text/SimpleDateFormat.html

like image 40
Subramanian Ramsundaram Avatar answered Oct 15 '22 03:10

Subramanian Ramsundaram