How can I format a date in java using "ff"?

I am trying to print the date in the following format:

"HHmmssff" 

I use SimpleDateFormatter. He fails because he cannot recognize "ff". Is there any other formatter? Or any other way to do this?

+3
source share
4 answers

S gives you a millisecond:

DateFormat formatter = new SimpleDateFormat ("hhmmssS");

with a substring you can disable the last 2 digits:

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

If you are looking for a second page in fractions (milliseconds), this example will be useful.

public class DateFormatter {
    public static void main(String[] args) {
        Date date = Calendar.getInstance().getTime();
        DateFormat formatter = new SimpleDateFormat("EEEE, dd MMMM yyyy, hh:mm:ss.SSS a");
        String today = formatter.format(date);
        System.out.println("Today : " + today);
    }
}

Conclusion: Today: Tuesday, May 24, 2011, 07:23: 30.627 pm

You see that the SSS in the formatter returns fractions of a second for you.

+4
source

f SimpleDateFormat.

f , , .

+1

, FF FF, ?

0

All Articles