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);
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.
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.
Class SimpleDateFormat. Deprecated. A class for parsing and formatting dates with a given pattern, compatible with the Java 6 API.
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With