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);
}
}
[결과]
'JAVA > Java Core' 카테고리의 다른 글
[JavaCore] 파일복사 및 이동 (0) | 2015.02.02 |
---|---|
[JavaCore] 파일생성 (0) | 2014.10.24 |
[JavaCore] 텍스트파일 한글 읽어들이기 (0) | 2014.10.24 |
[JavaCore] Java 실행 시 Argument 사용과 Option정의 (0) | 2014.09.03 |