Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Remove Leading "0" in day of month SimpleDateFormat

Is it possible to remove the "0" in January 04, 2012?

I am currently using the following Java to get the date format like

Monday, January 04, 2012

I would like for it to look like

Monday, January 4, 2012

    Date anotherCurDate = new Date();

    SimpleDateFormat formatter = new SimpleDateFormat("EEEE', 'MMMM dd', ' yyyy");  
    final String formattedDateString = formatter.format(anotherCurDate);

 final TextView currentRoomDate = (TextView)  this.findViewById(R.id.CurrentDate); 
like image 966
Denoteone Avatar asked Jan 12 '12 14:01

Denoteone


People also ask

How do you remove leading zeros from a date in Java?

For a Regular Expression approach, you can use: String shipDate = '04/06/2022'; // Option 1: shipDate = shipDate. replaceAll('\\b0(\\d)','$1'); // Option 2: shipDate = shipDate. replaceAll('\\b0',''); System.

How do you remove leading zeros from a string?

The replaceAll() method of the String class accepts two strings representing a regular expression and a replacement String and replaces the matched values with given String. The ^0+(?! $)"; To remove the leading zeros from a string pass this as first parameter and “” as second parameter.

Is SimpleDateFormat deprecated?

Class SimpleDateFormat. Deprecated. A class for parsing and formatting dates with a given pattern, compatible with the Java 6 API.


1 Answers

SimpleDateFormat formatter = new SimpleDateFormat("EEEE', 'MMMM d', ' yyyy");

Should do it (one 'd' instead of two)?

http://docs.oracle.com/javase/6/docs/api/java/text/SimpleDateFormat.html

like image 135
Jave Avatar answered Oct 19 '22 05:10

Jave