日期:2014-05-20  浏览次数:20701 次

提取系统时间??
1.怎样去提取系统的时间.有年月日,小时分,秒?????
2.怎样去用提取出的系统时间去跟年月日做比较(例:1985-01-01 09:12:01怎么样去判断他是否在1984-01-01至1985-01-04之间)

------解决方案--------------------
Java code

package test;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;

public class panel {

    public static void main(String[] args) throws ParseException {
        SimpleDateFormat sm = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        System.out.println(sm.format(new Date(System.currentTimeMillis())));

        Date date = sm.parse("1985-01-01 09:12:01");
        Date currentDate = new Date(System.currentTimeMillis());
        if(date.compareTo(currentDate)==-1) {
            System.out.println("date < currentDate");
        }else if(date.compareTo(currentDate)==0) {
            System.out.println("date = currentDate");
        }else if(date.compareTo(currentDate)==1) {
            System.out.println("date > currentDate");
        }
    }
}