반응형
String을 날짜 포맷으로 변환하기!
regTime : 20150522141253
reqTime : 20150428234211
위와 같은 String형식을..
2개의 format을 선언 한 뒤
DateFormat formatter = new SimpleDateFormat("yyyyMMddHHmmss"); SimpleDateFormat sdf = new SimpleDateFormat("yyyy/MM/dd HH:mm:ss"); |
아래처럼 작업을 해주면 됩니다.
try { }
|
변환 과정
regTime : 20150522141253
reqTime : 20150428234211
regTime2 : Fri May 22 14:12:53 KST 2015
reqTime2 : Tue Apr 28 23:42:11 KST 2015
regTme3 : 2015/05/22 14:12:53
reqTime3 : 2015/04/28 23:42:11
|
Date Format Pattern Syntax
You can design your own format patterns for dates and times from the list of symbols in the following table:
Symbol | Meaning | Presentation | Example |
---|---|---|---|
G | era designator | Text | AD |
y | year | Number | 2009 |
M | month in year | Text & Number | July & 07 |
d | day in month | Number | 10 |
h | hour in am/pm (1-12) | Number | 12 |
H | hour in day (0-23) | Number | 0 |
m | minute in hour | Number | 30 |
s | second in minute | Number | 55 |
S | millisecond | Number | 978 |
E | day in week | Text | Tuesday |
D | day in year | Number | 189 |
F | day of week in month | Number | 2 (2nd Wed in July) |
w | week in year | Number | 27 |
W | week in month | Number | 2 |
a | am/pm marker | Text | PM |
k | hour in day (1-24) | Number | 24 |
K | hour in am/pm (0-11) | Number | 0 |
z | time zone | Text | Pacific Standard Time |
' | escape for text | Delimiter | (none) |
' | single quote | Literal | ' |
더 좋은 방법이 있을지도 모르겠지만..이렇게 처리 했네요^^;
반응형
'Language > Java' 카테고리의 다른 글
2015년 06월 17일 이펙티브자바 스터디. (0) | 2015.06.17 |
---|---|
Favor composition over inheritance (0) | 2015.06.16 |
clone을 재정의할 때는 신중하라! (0) | 2015.06.11 |
hashCode() (0) | 2015.06.07 |
unicode 문제 해결(\u003d 등) (1) | 2015.01.12 |