Best way to convert Java SQL Date from yyyy-MM-dd to dd MMMM yyyy format

后端 未结 4 1373
有刺的猬
有刺的猬 2020-11-27 23:25

Is there a straightforward way of converting a Java SQL Date from format yyyy-MM-dd to dd MMMM yyyy format?

I could convert the date to a string and then manipulate

4条回答
  •  时光说笑
    2020-11-27 23:41

    It's not clear what you mean by a "Java SQL Date". If you mean as in java.sql.Date, then it doesn't really have a string format... it's just a number. To format it in a particular way, use something like java.text.SimpleDateFormat.

    Alternatively, convert it to a Joda Time DateTime; Joda Time is a much better date and time API than the built-in one. For example, SimpleDateFormat isn't thread-safe.

    (Note that a java.sql.Date has more precision than a normal java.util.Date, but it looks like you don't need that here.)

提交回复
热议问题