3. 系統時間與當前日期的區別? 系統時間確切的說應該是 System.currentTimeMillis(); new Date()是當前日期,雖然它getTime();和System.currentTimeMillis(); 一樣,但System.currentTimeMillis();
4. 如何計算兩個日期的天數差值? long beginTime = beginDate.getTime(); long endTime2 = endDate.getTime(); long betweenDays = (long)((endTime - beginTime) / (1000 * 60 * 60 *24) + 0.5);
5. 如何比較日期時間大??? 第一種方法: use Calendar object to compare java.util.Calendar class can be used to compare date. In order to do this, you guy should parse that string into int year, month, day and constrUCt a Calendar object, and then do comparison.
Below is a sample
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分鐘{}