how can I format a date in java with “ff”?

I’m trying to print a date with the following format:

"HHmmssff" 

I’m using SimpleDateFormatter. It fails because it can’t recognize "ff". Is there another formatter that can? Or any other way to do it?

Answer

S gives you millisecond:

DateFormat formatter = new SimpleDateFormat ("hhmmssS");

with substring, you may cut off the last 2 digits:

String d = formatter.format (new Date ());
System.out.println (d.substring (0, 7));

Leave a Reply

Your email address will not be published. Required fields are marked *