import java.util.*;
class getDate
{
public static void main(String[] args)
{
//String Dates = getDate(2013);
//sop(Dates);
String time = getTime();
sop(time);
}
/*
实现了获取任意年的二月份天数
*/
public static String getDate(int year)
{
Calendar c = Calendar.getInstance();
c.set(year,2,1);
c.add(Calendar.DAY_OF_MONTH,-1);
int y = c.get(Calendar.DAY_OF_MONTH);
String Dates =year+ "年的二月份天数是...."+y;
return Dates;
}
/*
2,获取昨天的现在这个时刻。
c.add(Calenar.DAY_OF_MONTH,-1);
*/
public static String getTime()
{
Calendar c = Calendar.getInstance();
c.add(Calendar.DAY_OF_MONTH,-1);
int YEAR =c.get(Calendar.YEAR);
int MONTH =c.get(Calendar.MONTH)+1;
int DATE=c.get(Calendar.DAY_OF_MONTH);
int WEEK=c.get(Calendar.DAY_OF_WEEK)+1;
int HOUR =c.get(Calendar.HOUR);
int MINUTE=c.get(Calendar.MINUTE);
int SECOND =c.get(Calendar.SECOND);
String[] weeks = {"","星期日","星期一","星期二","星期三","星期四","星期五","星期六",};
String WEEKS = weeks[WEEK];
return "昨天这个时候是:::" + YEAR+"年"+MONTH+"月"+DATE+"日:"+ WEEKS + ":"+ HOUR+"时"+MINUTE+"分" + SECOND + "秒";
}
public static void sop(Object obj)
{
System.out.println(obj);
}
} |
|