Java tutorial
//package com.java2s; //License from project: Apache License import java.util.Calendar; import java.util.Date; import java.util.Locale; public class Main { public static int getDatePart(Date date, int part) { if (date == null) return 0; Calendar cal = Calendar.getInstance(Locale.getDefault()); cal.setTime(date); return cal.get(part); } public static int getDatePart(long time, int part) { if (time <= 0) return 0; Calendar cal = Calendar.getInstance(Locale.getDefault()); cal.setTimeInMillis(time); return cal.get(part); } }