码迷,mamicode.com
首页 > 其他好文 > 详细

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

时间:2019-06-17 17:05:39      阅读:88      评论:0      收藏:0      [点我收藏+]

标签:时间   gets   end   nbsp   day   col   tin   lis   gettime   

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();
}

 

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

标签:时间   gets   end   nbsp   day   col   tin   lis   gettime   

原文地址:https://www.cnblogs.com/cq-yangzhou/p/11040670.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!