public class DateDemo {
public static void main(String[] args) {
Date d= new Date();
System.out.println(d);
//将模式封装到SimpleDateformat对象中
SimpleDateFormat sdf= new SimpleDateFormat("yyyy年MM月dd日 hh::mm::ss");
//调用format方法让模式格式化指定Date对象。
String time =sdf.format(d);
System.out.println(time);
//输出特定时间
long nowtime= System.currentTimeMillis();
Date nowdate=new Date(nowtime);
String now=sdf.format(nowdate);
System.out.println(now);
}
}
4)日历Calendar对象
import java.util.Calendar;
public class CalendarDemo {
public static void main(String[] args) {
String[] weeks = new String[]{"星期日","星期一","星期二","星期三","星期四","星期五","星期六"};
String[] moth= new String[]{"一月","二月","三月","四月","五月","六月","七月","八月","九月","十月","十一月","十二月"};
Calendar c=Calendar.getInstance();
int yearindex=c.get(Calendar.YEAR);
int weekindex=c.get(Calendar.DAY_OF_WEEK);
int mothindex=c.get(Calendar.MONTH);