AFAIK there is no template in SimpleDateFormat for this.
The easiest way is the easiest. Check the length of the string and add extra space if necessary. Since all other elements have a fixed length, there is no need for a more complex check.
SimpleDateFormat sdff = new SimpleDateFormat("MMM d HH:mm:ss"); if (sdff.length == 14) { sdff = sdff.substring(0,4) + " " + sdff.substring(4); }
If you want it to be fantastic (like RegExp), it's a little more reliable, but not worth the effort IMO
SimpleDateFormat sdff = new SimpleDateFormat("MMM d HH:mm:ss"); sdff = sdff.replaceAll(" (\\d) ", " $1 ");
source share