2019년 9월 21일 토요일

[Java] 시간 출력하기 - SimpleDateFormat

SimpleDateFormat을 이용하여 시간을 원하는 포멧으로 출력할 수 있다.

SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss", Locale.KOREA);
SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm", Locale.KOREA);
SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH", Locale.KOREA);
SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd", Locale.KOREA);

// if need UTC
format.setTimeZone(TimeZone.getTimeZone("UTC"));

String time = format.format( new Date() );

댓글 없음:

댓글 쓰기