Java: Extend SimpleDateFormat with new pattern letters

Posted by Adam Matan on Stack Overflow See other posts from Stack Overflow or by Adam Matan
Published on 2012-11-25T10:54:44Z Indexed on 2012/11/25 11:03 UTC
Read the original article Hit count: 219

Filed under:
|
|
|

Java's SimpleDateFormat is used to format a Date object to a string. The formatter supports various pattern letters, which denote textual representation of a Date field. For example, yy is two-letter year, yyyy is four-letter year, and E is day of week.

For example, A SimpleDateFormat initialized with yyyy.MM.dd G 'at' HH:mm:ss z will format a date to something like 2001.07.04 AD at 12:08:56 PDT.

I would like to add some pattern letters to SimpleDateFormat. For example, want C to denote Hebrew weekday (??? ?????, ??? ???, ...).

What's the right way to extend SimpleDateFormat with these new pattern letters? The only online example I could find seems somewhat complicated. I can live with formatting only, without parsing.

© Stack Overflow or respective owner

Related posts about java

Related posts about date