//得到当前时间
    Calendar cal = new GregorianCalendar();    int hour12 = cal.get(Calendar.HOUR);            // 12制小时
    int hour24 = cal.get(Calendar.HOUR_OF_DAY);     // 24制小时
    int min = cal.get(Calendar.MINUTE);             // 分
    int sec = cal.get(Calendar.SECOND);             // 秒不知道你有什么具体要求?

解决方案 »

  1.   

    Date dNow = new Date();
    String str = "2002-3-20 15:07:40";
    Date dt = new SimpleDateFormat("yyyy-MM-dd H:m:s").parse(str);
    long lgTime = dt.getTime();
    long lgNow = dNow.getTime();
    int tt = (lgNow-lgTime)/1000;是不你想要我东西?
      

  2.   

    新鲜出炉
    刚刚写完的,看看符合要求吗?
    具体的可以自己改动改动import java.util.*;public class Test{  //要比较的一天中的某个时刻,下面是指定的三个参数,小时,分钟,秒数。
      private final static int specifiedHour = 18;
      private final static int specifiedMinute = 0;
      private final static int specifiedSecond = 0;  //取得当前的时间,然后使用当前的年份,月份,日期来创建特定的时间。
      //然后两者相减。注意最后得到的毫秒数,所以必须除以1000才是正确结果
      public static void main(String[] args){
        GregorianCalendar currentGC = new GregorianCalendar();    int standardYear = currentGC.get( Calendar.YEAR );
        int standardMonth = currentGC.get( Calendar.MONTH );
        int standardDay = currentGC.get( Calendar.DAY_OF_MONTH );    GregorianCalendar standardGC = new GregorianCalendar(
          standardYear, standardMonth, standardDay, specifiedHour, specifiedMinute, specifiedSecond );   System.out.println( ( currentGC.getTime().getTime() - standardGC.getTime().getTime() ) / 1000 );
      }
    }