Java date format – including additional characters

Sure, with the SimpleDateFormat you can include literal strings:

Within date and time pattern strings, unquoted letters from ‘A’ to ‘Z’ and from ‘a’ to ‘z’ are interpreted as pattern letters representing the components of a date or time string. Text can be quoted using single quotes (‘) to avoid interpretation. “”” represents a single quote. All other characters are not interpreted; they’re simply copied into the output string during formatting or matched against the input string during parsing.

 "hh 'o''clock' a, zzzz"    12 o'clock PM, Pacific Daylight Time

Leave a Comment