Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 818
AAaa Avatar asked May 24 '11 13:05

AAaa


1 Answers

If you are looking for printing second in fractions (milliseconds), this example will be helpful.

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);
    }
}

Output: Today : Tuesday, 24 May 2011, 07:23:30.627 PM

You see SSS in the formatter returns fractions of seconds for you.

like image 107
gtiwari333 Avatar answered Sep 25 '22 17:09

gtiwari333