Posted on 2006-11-05 17:52
苑 阅读(144)
评论(0) 编辑 收藏 所属分类:
java基础学习系列
import
java.util.Calendar;
public class
MainClass
{
public static
void
main
(
String args
[]) {
String months
[]
=
{
"Jan"
,
"Feb"
,
"Mar"
,
"Apr"
,
"May"
,
"Jun"
,
"Jul"
,
"Aug"
,
"Sep"
,
"Oct"
,
"Nov"
,
"Dec"
}
;
Calendar calendar = Calendar.getInstance
()
;
System.out.print
(
"Date: "
)
;
System.out.print
(
months
[
calendar.get
(
Calendar.MONTH
)])
;
System.out.print
(
" "
+ calendar.get
(
Calendar.DATE
)
+
" "
)
;
System.out.println
(
calendar.get
(
Calendar.YEAR
))
;
System.out.print
(
"Time: "
)
;
System.out.print
(
calendar.get
(
Calendar.HOUR
)
+
":"
)
;
System.out.print
(
calendar.get
(
Calendar.MINUTE
)
+
":"
)
;
System.out.println
(
calendar.get
(
Calendar.SECOND
))
;
calendar.set
(
Calendar.HOUR,
10
)
;
calendar.set
(
Calendar.MINUTE,
29
)
;
calendar.set
(
Calendar.SECOND,
22
)
;
System.out.print
(
"Updated time: "
)
;
System.out.print
(
calendar.get
(
Calendar.HOUR
)
+
":"
)
;
System.out.print
(
calendar.get
(
Calendar.MINUTE
)
+
":"
)
;
System.out.println
(
calendar.get
(
Calendar.SECOND
))
;
}
}