Custom milliseconds date and time string

I have time in milliseconds for ex. 1308700800000; I need to convert it to something like Jun 9'11 at 02:15 PM.

I tried to use

SimpleDateFormat format = new SimpleDateFormat("MMM D'\''YY");

but I get an exception:

Caused by: java.lang.IllegalArgumentException: Unterminated quote

Any help would be greatly appreciated.

+5
source share
3 answers

The exception message shows that the problem will be related to your format string, in particular around a separate part of the quotation marks.

Looking at the documentation , we can see that:

('), . "'" " .

, , ( ) ,

new SimpleDateFormat("MMM d''yy")

.

+11

:

import java.util.*;
import java.text.*;

class D {
    public static void main( String ... args )  {
        System.out.println( 
            new SimpleDateFormat("MMM dd''yy")
            .format( new Date( 1308700800000L  ))
        );
    }
}

:

Jun 21'11
+3

Andrzej is right, but Caps D and Y will not work for you. Read the document, but which should work:

SimpleDateFormat format = new SimpleDateFormat("MMM d''yy 'at' HH:mm:ss z")
+2
source

All Articles