Java date format - including additional characters

前端 未结 5 1100
清歌不尽
清歌不尽 2020-12-05 03:50

Is there an equivalent to php date() style formatting in Java? I mean, in php I can backslash-escape characters to have them treated literally. I.e. yyyy \\y\\e\\a\\

5条回答
  •  旧巷少年郎
    2020-12-05 04:08

    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
    

提交回复
热议问题