2012-10-31
java] SimpleDateFormate 예제
출처 : http://www.ssial.com/141
import java.text.SimpleDateFormat;
.
.
.
Format formatter;
// The year
formatter = new SimpleDateFormat("yy"); // 02
formatter = new SimpleDateFormat("yyyy"); // 2002
// The month
formatter = new SimpleDateFormat("M"); // 1
formatter = new SimpleDateFormat("MM"); // 01
formatter = new SimpleDateFormat("MMM"); // Jan
formatter = new SimpleDateFormat("MMMM"); // January
// The day
formatter = new SimpleDateFormat("d"); // 9
formatter = new SimpleDateFormat("dd"); // 09
// The day in week
formatter = new SimpleDateFormat("E"); // Wed
formatter = new SimpleDateFormat("EEEE"); // Wednesday
// Get today's date
Date date = new Date();
// Some examples
formatter = new SimpleDateFormat("MM/dd/yy");
String s = formatter.format(date);
// 01/09/02
formatter = new SimpleDateFormat("dd-MMM-yy");
s = formatter.format(date);
// 29-Jan-02
// Examples with date and time; see also
// e316 Formatting the Time Using a Custom Format
formatter = new SimpleDateFormat("yyyy.MM.dd.HH.mm.ss");
s = formatter.format(date);
// 2002.01.29.08.36.33
formatter = new SimpleDateFormat("E, dd MMM yyyy HH:mm:ss Z");
s = formatter.format(date);
// Tue, 09 Jan 2002 22:14:02 -0500
// The hour (1-12)
formatter = new SimpleDateFormat("h"); // 8
formatter = new SimpleDateFormat("hh"); // 08
// The hour (0-23)
formatter = new SimpleDateFormat("H"); // 8
formatter = new SimpleDateFormat("HH"); // 08
// The minutes
formatter = new SimpleDateFormat("m"); // 7
formatter = new SimpleDateFormat("mm"); // 07
// The seconds
formatter = new SimpleDateFormat("s"); // 3
formatter = new SimpleDateFormat("ss"); // 03
// The am/pm marker
formatter = new SimpleDateFormat("a"); // AM
// The time zone
formatter = new SimpleDateFormat("z"); // PST
formatter = new SimpleDateFormat("zzzz"); // Pacific Standard Time
formatter = new SimpleDateFormat("Z"); // -0800
// Get today's date
Date date = new Date();
// Some examples
formatter = new SimpleDateFormat("hh:mm:ss a");
String s = formatter.format(date);
// 01:12:53 AM
formatter = new SimpleDateFormat("HH.mm.ss");
s = formatter.format(date);
// 14.36.33
출처: http://www.exampledepot.com/egs/java.text/pkg.html#Times
라벨:
자바,
프로그래밍,
java,
programing,
simpleDataFormate
피드 구독하기:
댓글 (Atom)
댓글 없음:
댓글 쓰기