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(); }
原文地址:https://www.cnblogs.com/cq-yangzhou/p/11040670.html
时间: 2024-10-11 12:23:10