import java.text.SimpleDateFormat;

import java.util.Date;

  

public class GetTimeExample {

 

       private static Date date;

      

       static SimpleDateFormat format1 = new SimpleDateFormat("yyyy-MM-dd");

       static SimpleDateFormat format2 = new SimpleDateFormat("yyyy-MM-dd hh:mm:ss");

       static SimpleDateFormat format3 = new SimpleDateFormat("yyyy-MM-dd-hh-mm-ss");

       static SimpleDateFormat format4 = new SimpleDateFormat("yyyy_MM_dd");

       static SimpleDateFormat format5 = new SimpleDateFormat("yyyy_MM_dd_hh_mm");

       static SimpleDateFormat format6 = new SimpleDateFormat("yyyy*MM*dd");

    static SimpleDateFormat format7 = new SimpleDateFormat("yyyyMMdd");

      

       public static void main(String[] args) {

             date = new Date();

            

             trace(format1.format(date));

             trace(format2.format(date));

             trace(format3.format(date));

             trace(format4.format(date));

             trace(format5.format(date));

             trace(format6.format(date));

  trace(format7.format(date));

       }

 

       private static void trace(String msg)

       {

             System.out.println(msg);

       }

            

}



[결과]

저작자 표시 비영리 변경 금지
신고
YOUR COMMENT IS THE CRITICAL SUCCESS FACTOR FOR THE QUALITY OF BLOG POST