[JavaCore] 시간구하기
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);
}
}
[결과]