开发者

Android date format using SimpleDate

I am working on an XML Parser for Android with twelve different items and I need help creating a date for e开发者_运维技巧ach item. This is what I have so far:

TextView detailsPubdate = (TextView)findViewById(R.id.detailspubdate);

I am looking to make the date look like this: Saturday, September 3. Thank you for your help!


If you are looking for todays date, you can do this by using the Date object.

Date today = new Date();//this creates a date representing this instance in time.

Then pass the date to the SimpleDateFormat.format(Date) method.

// "EEEE, MMMM, d" is the pattern to use to get your desired formatted date.
SimpleDateFormat sdf = new SimpleDateFormat("EEEE, MMMM, d");
String formattedDate = sdf.format(today);

Finally, you can set this String into your TextView

detailsPubdate.setText(formattedDate);

Here is the documentation for SimpleDateFormat. The documentation shows the various patterns available to format Date objects.


use the DateFormat class to format your dates.

Example:

     DateFormat formatter = new SimpleDateFormat("EEE, MMM d");
    Date date = (Date) formatter.parse("02.47.44 PM");
detailsPubdate.setText(date.toString());

This is the java documentation for SimpleDateFormatter if you want to change your pattern.


It is not very clear what you are trying to do, but you could use the following to format date:

   SimpleDateFormat sdf=new SimpleDateFormat("EEEE, MMMM, d");
   //get current date
   Date date=new Date();
   String dateString=sdf.format(date);

You should have a look at the SimpleDateFormat class.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜