List of usage examples for java.util Calendar setTime
public final void setTime(Date date)
Date
. From source file:Main.java
public static int getYear() { Calendar c = Calendar.getInstance(); c.setTime(new Date()); int year = c.get(Calendar.YEAR); return year;//from w ww . j a v a 2s . c o m }
From source file:Main.java
public static int getHour() { Calendar c = Calendar.getInstance(); c.setTime(new Date()); int hour = c.get(Calendar.HOUR_OF_DAY); return hour;/*from w w w . ja va2 s . co m*/ }
From source file:Main.java
public static int getMonth() { Calendar c = Calendar.getInstance(); c.setTime(new Date()); int year = c.get(Calendar.MONTH); return year;/* w ww .ja v a 2s .c o m*/ }
From source file:Main.java
public static int getMinutes() { Calendar c = Calendar.getInstance(); c.setTime(new Date()); int minute = c.get(Calendar.MINUTE); return minute; }
From source file:Main.java
public static int getDayOfYear() { Calendar c = Calendar.getInstance(); c.setTime(new Date()); int year = c.get(Calendar.DAY_OF_YEAR); return year;/* w ww . j a va 2 s . c om*/ }
From source file:Main.java
public static Calendar getDateComparedToCurrent(Calendar current, int daysToAdd) { Calendar cal = Calendar.getInstance(); cal.setTime(current.getTime()); cal.add(Calendar.DATE, daysToAdd); return cal;/*w ww.j a v a2s. co m*/ }
From source file:Main.java
public static int getDayOfWeek() { Calendar cal = Calendar.getInstance(); cal.setTime(new Date()); return cal.get(Calendar.DAY_OF_WEEK) - 1; }
From source file:Main.java
public static Date addDays(Date date, int days) { Calendar cal = Calendar.getInstance(); cal.setTime(date); cal.add(Calendar.DATE, days); //minus number would decrement the days return cal.getTime(); }
From source file:Main.java
public static Date getDateBefore(Date d, int day) { Calendar now = Calendar.getInstance(); now.setTime(d); now.set(Calendar.DATE, now.get(Calendar.DATE) - day); return now.getTime(); }
From source file:Main.java
public static int getYear(Date date) { Calendar c = Calendar.getInstance(); c.setTime(date); return c.get(Calendar.YEAR); }