본문 바로가기

꿀팁 활용

[java]자바 datetime 포맷 정리

    Date date = new Date();
	date.setTime(System.currentTimeMillis());

    String datePattern1 = "yyyyMMdd";
    SimpleDateFormat format1 = new SimpleDateFormat(datePattern1);
	System.out.println(format1.format(date));

    String datePattern2 = "EE MMM d, yy";
    SimpleDateFormat format2 = new SimpleDateFormat(datePattern2);
	System.out.println(format2.format(date));

    String datePattern3 = "h:mm a EE MMM d, yy";
    SimpleDateFormat format3 = new SimpleDateFormat(datePattern3);
	System.out.println(format3.format(date));

    String datePattern4 = "yyyyy.MMMMM.dd GGG hh:mm aaa";
    SimpleDateFormat format4 = new SimpleDateFormat(datePattern4);
	System.out.println(format4.format(date));

    String datePattern5 = "yyyy-MM-dd'T'HH:mm:ss.SSSZ";
    SimpleDateFormat format5 = new SimpleDateFormat(datePattern5);
	System.out.println(format5.format(date))