返回指定时间的年、月、日、小时、 分钟、 秒 毫秒

参考地址:http://yuncode.net/code/c_5194eee4e69e95

1、获取年

public static int getYear(Date date){
        Calendar c = Calendar.getInstance();
        c.setTime(date);
        return c.get(Calendar.YEAR);
    }

2、获取月

public static int getMonth(Date date){
        Calendar c = Calendar.getInstance();
        c.setTime(date);
        return c.get(Calendar.MONTH)+1;
    }

3、获取日

public static int getMonth(Date date){
        Calendar c = Calendar.getInstance();
        c.setTime(date);
        return c.get(Calendar.DAY_OF_MONTH);
    }

4、获取小时

public static int getHour(Date date) {
    calendar = Calendar.getInstance();
    calendar.setTime(date);
    return calendar.get(Calendar.HOUR_OF_DAY);
}

5、获取分钟

public static int getMinute(Date date) {
    calendar = Calendar.getInstance();
    calendar.setTime(date);
    return calendar.get(Calendar.MINUTE);
}

6、获取秒

public static int getSecond(Date date) {
    calendar = Calendar.getInstance();
    calendar.setTime(date);
    return calendar.get(Calendar.SECOND);
}

7、获取毫秒

public static long getMillis(Date date) {
    calendar = Calendar.getInstance();
    calendar.setTime(date);
    return calendar.getTimeInMillis();
}

 

posted @ 2019-06-17 16:53  炫舞风中  阅读(210)  评论(0编辑  收藏  举报