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

后端 未结 4 1372
有刺的猬
有刺的猬 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:47

    If it is for presentation you can use SimpleDateFormat straight away:

    package org.experiment;
    
    import java.sql.Date;
    import java.text.SimpleDateFormat;
    
    public class Dates {
        private static SimpleDateFormat df = new SimpleDateFormat("MMMM yyyy");
    
        public static void main(String[] args){
    
            Date oneDate = new Date(new java.util.Date().getTime());
            System.out.println(df.format(oneDate));
        }
    
    }
    

提交回复
热议问题