Is it possible to get java.util.Date object with specific format?

前端 未结 2 1989
太阳男子
太阳男子 2021-01-15 14:37

I would like to ask about the usage of java.util.Date. Here is my sample class

         public class DateConverter {
           public static void main(Strin         


        
2条回答
  •  野的像风
    2021-01-15 15:28

    Yes, extend Date adding the format field and override toString method, something along the lines of

    public class DateWithFormat extends Date {
       String format; // Assign as appropriate
       public String toString() {
         return new SimpleDateFormat(format).format(this));
       } 
    }
    

提交回复
热议问题