java.text.SimpleDateFormat

 

SimpleDateFormat is a concrete class for formatting and parsing dates in a locale-sensitive manner. It allows for formatting (date -> text), parsing (text -> date), and normalization.

 

참조 URL

http://docs.oracle.com/javase/1.4.2/docs/api/java/text/SimpleDateFormat.html

 

사용예시

Date today = new Date();
SimpleDateFormat format = new SimpleDateFormat("yyyyMMdd");
System.out.println(format.format(today));

 

아래는 API에 정의 되어 있는 패턴이다.

(all other characters from 'A' to 'Z' and from 'a' to 'z' are reserved)

 

Letter Date or Time Component Presentation Examples
G Era designator Text AD
y Year Year 1996; 96
M Month in year Month July; Jul; 07
w Week in year Number 27
W Week in month Number 2
D Day in year Number 189
d Day in month Number 10
F Day of week in month Number 2
E Day in week Text Tuesday; Tue
a Am/pm marker Text PM
H Hour in day (0-23) Number 0
k Hour in day (1-24) Number 24
K Hour in am/pm (0-11) Number 0
h Hour in am/pm (1-12) Number 12
m Minute in hour Number 30
s Second in minute Number 55
S Millisecond Number 978
z Time zone General time zone Pacific Standard Time; PST; GMT-08:00
Z Time zone RFC 822 time zone -0800

 

 

아래는 US 로케일 정보를 기반한 예시이다.

 

// 2001.07.04 AD at 12:08:56 PDT

new SimpleDateFormat("yyyy.MM.dd G 'at' HH:mm:ss z", Locale.US)

 

// Wed, Jul 4, '01

new SimpleDateFormat("EEE, MMM d, ''yy", Locale.US)


// 12:08 PM

new SimpleDateFormat("h:mm a", Locale.US)

 

// 12 o'clock PM, Pacific Daylight Time

new SimpleDateFormat("hh 'o''clock' a, zzzz", Locale.US)

 

// 0:08 PM, PDT

new SimpleDateFormat("K:mm a, z", Locale.US)

 

// 02001.July.04 AD 12:08 PM

new SimpleDateFormat("yyyyy.MMMMM.dd GGG hh:mm aaa", Locale.US)

 

// Wed, 4 Jul 2001 12:08:56 -0700 

new SimpleDateFormat("EEE, d MMM yyyy HH:mm:ss Z", Locale.US)

 

// 010704120856-0700 

new SimpleDateFormat("yyMMddHHmmssZ", Locale.US)

 

 

아래는 KO 로케일 정보를 기반한 예시이다.

 

// 2012년 07월 04일 수요일
new SimpleDateFormat("yyyy년 MM월 dd일 E요일");


// 2012-07-04 10:10:51 오전
new SimpleDateFormat("yyyy-MM-dd hh:mm:ss a");

 

 

감사합니다 :)

 

Posted by 리트모스
: