Java date format - including additional characters

前端 未结 5 1098
清歌不尽
清歌不尽 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:23

    You can use String.format as documented in java.util.Formatter:

    Calendar c = ...;
    String s = String.format("%tY year", c);
    // -> s == "2010 year" or whatever the year actually is
    

提交回复
热议问题