List of usage examples for java.util Calendar setTime
public final void setTime(Date date)
Date
. From source file:Main.java
public static Date addMinutes(Date date, int min) { if (date == null) { return null; }/* w ww.j av a2 s .c o m*/ Calendar calendar = Calendar.getInstance(); calendar.setTime(date); calendar.add(Calendar.MINUTE, min); return calendar.getTime(); }
From source file:Main.java
public static String getMonthStringFromDate(Date date) { Calendar calendar = Calendar.getInstance(); calendar.setTime(date); StringBuilder sb = new StringBuilder(); sb.append(calendar.getDisplayName(Calendar.MONTH, Calendar.LONG, Locale.US)).append(", ") .append(calendar.get(Calendar.YEAR)); return sb.toString(); }
From source file:Main.java
public static Date getDateStart(Date date) { Calendar calendar = Calendar.getInstance(); calendar.setTime(date); calendar.set(Calendar.HOUR_OF_DAY, 0); calendar.set(Calendar.MINUTE, 0); calendar.set(Calendar.SECOND, 0); return calendar.getTime(); }
From source file:Main.java
public static int getCurWeekNum() { Calendar c = Calendar.getInstance(); c.setTime(new Date(System.currentTimeMillis())); int currentDayOfYear = c.get(Calendar.DAY_OF_YEAR) - 5; int distanceday; if (currentDayOfYear > 56 && currentDayOfYear < 244) { distanceday = currentDayOfYear - 56; } else if (currentDayOfYear > 244) { distanceday = currentDayOfYear - 244; } else {/* ww w. j a v a2 s .c om*/ return 0; } return distanceday / 7 + 1; }
From source file:Main.java
/** * Get the SunSet for the given date//from w w w .ja v a2 s . c o m * @param date - input date * @return - Date with time specifying the Sun Set */ public static Date getSunSet(Date date) { Calendar cal = Calendar.getInstance(); cal.setTime(date); cal.set(Calendar.HOUR_OF_DAY, 18); cal.set(Calendar.MINUTE, 00); cal.set(Calendar.SECOND, 0); cal.set(Calendar.MILLISECOND, 0); Date ret = cal.getTime(); return ret; }
From source file:Main.java
public static Date getDateEnd(Date date) { Calendar calendar = Calendar.getInstance(); calendar.setTime(date); calendar.set(Calendar.HOUR_OF_DAY, 23); calendar.set(Calendar.MINUTE, 59); calendar.set(Calendar.SECOND, 59); return calendar.getTime(); }
From source file:Util.java
public static int getDayOfMonthFromDate(Date date) { Calendar calendar = Calendar.getInstance(); calendar.setTime(date); return calendar.get(Calendar.DAY_OF_MONTH); }
From source file:Util.java
public static int getMonthFromDate(Date date) { Calendar calendar = Calendar.getInstance(); calendar.setTime(date); return calendar.get(Calendar.MONTH); }
From source file:Util.java
public static int getYearFromDate(Date date) { Calendar calendar = Calendar.getInstance(); calendar.setTime(date); return calendar.get(Calendar.YEAR); }
From source file:Main.java
/** * Get the SunRise for the given date//from ww w .j a va2 s.c om * @param date - input date * @return - Date with time specifying the Sun Rise */ public static Date getSunRise(Date date) { Calendar cal = Calendar.getInstance(); cal.setTime(date); cal.set(Calendar.HOUR_OF_DAY, 06); cal.set(Calendar.MINUTE, 00); cal.set(Calendar.SECOND, 0); cal.set(Calendar.MILLISECOND, 0); Date ret = cal.getTime(); return ret; }