i want to display the current date in this format Wednesday march 28,2012 , i wrote a method to get this format but it gives invalid values of the date (since when i run the code it gives Saturday sep2,1933) why is that ? what is the error in my code?
this is my code:
public class AddExercise extends Activity
{
private Date exercise_date;
private TextView date_Txt;
Calendar localCalendar = Calendar.getInstance();
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.add_exercise);
int year = localCalendar.get(Calendar.YEAR);
int month = localCalendar.get(Calendar.MONTH);
int day = localCalendar.get(Calendar.DAY_OF_MONTH);
exercise_date = new Date(day, month , yr);
date_Txt=(TextView)findViewById(R.id.date);
String x=formatdate(exercise_date, "EEEE MMM d, yyyy");
date_Txt.setText(x);
}
public static String formatdate(Date paramDate, String paramString)
{
String str;
if (paramDate != null)
{
if (paramString == null)
paramString = "MMMM dd, yyyy";
str = new SimpleDateFormat(paramString).format(paramDate);
}
else
{
str = null;
}
return str;
}
}
This is primarily because you are using deprecated
Date()constructor.It requires following Parameters:
year – the year minus 1900.
month – the month between 0-11.
date – the day of the month between 1-31.
But you are passing incorrect year altogether
Why don’t you simply do this:
or better yet
Instead of jumping through all the hoops?