Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>You can simply remove the ".":</p> <pre><code>df2.format(new Date()).replaceAll("\\.", "")); </code></pre> <hr/> <p>Edit, regarding the <em>lemon</em> answer:</p> <p>It seems to be a problem with the formatting when using the Locale French. Thus, I suggest that you simply use the <code>.</code> removal as I explained.</p> <p>Indeed, the following code:</p> <pre><code> String format2 = "dd-MMM-yy"; Date date = Calendar.getInstance().getTime(); SimpleDateFormat sdf = new SimpleDateFormat(format2, Locale.FRENCH); System.out.println(sdf.format(date)); sdf = new SimpleDateFormat(format2, Locale.ENGLISH); System.out.println(sdf.format(date)); </code></pre> <p>displays the following output:</p> <pre><code>28-oct.-09 28-Oct-09 </code></pre> <hr/> <p><em>Edit again</em></p> <p>Ok, I got your problem right now.</p> <p>I don't really know how you can solve this problem without processing your String first. The idea is to replace the month in the original String by a comprehensive month:</p> <pre><code> String[] givenMonths = { "jan", "fév", "mars", "avr.", "mai", "juin", "juil", "août", "sept", "oct", "nov", "déc" }; String[] realMonths = { "janv.", "févr.", "mars", "avr.", "mai", "juin", "juil.", "août", "sept.", "oct.", "nov.", "déc." }; String original = "09-oct-08"; for (int i = 0; i &lt; givenMonths.length; i++) { original = original.replaceAll(givenMonths[i], realMonths[i]); } String format2 = "dd-MMM-yy"; DateFormat df2 = new SimpleDateFormat(format2, Locale.FRENCH); Date date = df2.parse(original); System.out.println("--&gt; " + date); </code></pre> <p>I agree, this is awful, but I don't see any other solution if you use to <code>SimpleDateFormat</code> and <code>Date</code> classes.</p> <p>Another solution is to use a <strong>real</strong> date and time library instead of the original JDK ones, such as <a href="http://joda-time.sourceforge.net/" rel="nofollow noreferrer">Joda Time</a>.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload