아무거나

Date 표시 방법 본문

Java & Kotlin/Java

Date 표시 방법

전봉근 2019. 6. 19. 10:18
반응형

[코드예제]

import java.text.SimpleDateFormat;
import java.util.Calendar;

Calendar cal = Calendar.getInstance();
cal.add(Calendar.DATE, 1);
SimpleDateFormat format1 = new SimpleDateFormat("yyyy-MM-dd");

// Output "Wed Sep 26 14:23:28 EST 2012"
System.out.println(cal.getTime());

String formatted = format1.format(cal.getTime());

// Output "2012-09-26"
System.out.println(formatted);

// Output "Wed Sep 26 00:00:00 EST 2012"
System.out.println(format1.parse(formatted));

Calendar cal = Calendar.getInstance();
cal.add(Calendar.DATE, 1);
SimpleDateFormat dateObj = new SimpleDateFormat("yyyyMMdd");

// 20120926​ 
String formatted = dateObj.format(cal.getTime());
model.addAttribute("serverTime", formatted );
반응형
Comments