G:紀元(西暦)
y:年
M:月
w:年における週
W:月における週
D:年における日
d:月における日
F:月における曜日
E:曜日
a:午前/午後
H:一日における時(0~23)
k:一日における時(1~24)
K:午前/午後の時(0~11)
h:午前/午後の時(1~12)
m:分
s:秒
S:ミリ秒
z:タイムゾーン(一般的なタイムゾーン)
Z:タイムゾーン(RFC 822 タイムゾーン)
例.
"yyyy/M/d" ⇒ "2008/8/5"
"yy年MM月dd日" ⇒ "08年08月05日"
フォーマット済みテキストを得る
引数にはCalendarのgetTimeを利用してDateインスタンスを渡すようにする
String = DateFormat.format(DATE);
例.
public class DateFormatApp extends Frame{
private static final long serialVersionUID = 1L;
public static void main(String[] args) {
// TODO 自動生成されたメソッド・スタブ
new DateFormatApp();
}
public DateFormatApp(){
this.setSize(300,200);
Label l1 = new Label();
l1.setFont(new Font("Serif",Font.BOLD,18));
this.add(l1,BorderLayout.CENTER);
Calendar c1 = new GregorianCalendar();
SimpleDateFormat df = new SimpleDateFormat("MM月dd日(E)~Gyyyy年~");
l1.setText(df.format(c1.getTime()));
this.setVisible(true);
}
}
0 件のコメント:
コメントを投稿