2.
t=Calendar.getInstance();m=t.get(t.MONTH)+1;
这里为什么要加一?
long beginTime = beginDate.getTime();
long endTime2 = endDate.getTime();
long betweenDays = (long)((endTime - beginTime) / (1000 * 60 * 60 *24) + 0.5);
这个是两个日期如果之间的天数差但是要算小时
String date1 = "1987-01-01";
String date2 = "2010-01-01";
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-mm-dd");
Date d1 = sdf.parse(date1);
Date d2 = sdf.parse(date2);
long daysBetween = (d2.getTime() - d1.getTime() + 1000000) / (3600 * 24 * 1000);
System.out.println("1987-01-01 与 2010-01-01 相隔 " + daysBetween + " 天");
这个是只是算日期不算小时
StringTokenizer token = new StringTokenizer(your string,"-");
int year = Integer.parseInt(token.nextToken());
int month = Integer.parseInt(token.nextToken());
int day = Integer.parseInt(token.nextToken());
Calendar date = Calendar.getInstance();
date.set(year,month,day);
Calendar today = Calendar.getInstacne();
if(date.after(today)){
//......
}
Date nowDate=new Date();//当前时间\r
long nowTime=nowDate.getTime;
long lastTime=userTime.longValue();//以前的时间\r
long time=nowTime-lastTime;//时间相减比较。
if(time>(long)60000)//1分钟{}
java.text.SimpleDateFormat formatter = new java.text.SimpleDateFormat("yyyy-MM-dd");
String riqi=formatter.format(currentTime_1);
第二次求时间
java.text.DateFormat format1 = new java.text.SimpleDateFormat("hhmmss");
java.util.Date currentTime_2 = new java.util.Date();
String shijian=format1.format(currentTime_2);
java.text.SimpleDateFormat formatter = new java.text.SimpleDateFormat("yyyy-MM-dd-H-mm-ss");
java.util.Date currentTime_1 = new java.util.Date();
String str_date = formatter.format(currentTime_1);
StringTokenizer token = new StringTokenizer(str_date,"-");
String year = token.nextToken();
String month= token.nextToken();
String day = token.nextToken();
String hh = token.nextToken();
String mm = token.nextToken();
String ss = token.nextToken();
String riqi=year+"年\\"+month+"月"+day+"日"+" "+hh+"点\\"+mm+"分"+ss+"秒\\";
String newdir=year+month+day;
String wenjian = hh+mm+ss;
java.util.Calendar date = java.util.Calendar.getInstance();
System.out.println(date.getActualMaximum(date.DAY_OF_MONTH));
8.前一个月的日期
Calendar calendar = Calendar.getInstance();
calendar.add(Calendar.DATE,0);//得到当前一天(如果前一天就-1)
calendar.add(Calendar.MONTH, -1);//得到前一个月
Date date=calendar.getTime();
SimpleDateFormat dateFormat = new SimpleDateFormat( "yyyy-MM-dd HH:mm:ss");
CharSequence time = dateFormat.format(date);