List of usage examples for java.util Calendar set
public void set(int field, int value)
From source file:Main.java
public static java.util.Date getDateEnd(java.util.Date d) { Calendar c = Calendar.getInstance(); c.clear();// ww w . ja v a2 s . c o m Calendar co = Calendar.getInstance(); co.setTime(d); c.set(Calendar.DAY_OF_MONTH, co.get(Calendar.DAY_OF_MONTH)); c.set(Calendar.MONTH, co.get(Calendar.MONTH)); c.set(Calendar.YEAR, co.get(Calendar.YEAR)); c.add(Calendar.DAY_OF_MONTH, 1); c.add(Calendar.MILLISECOND, -1); return c.getTime(); }
From source file:Main.java
public static Calendar transformStringTimeToCalendar(String time) { Calendar calendar = Calendar.getInstance(); String[] split = time.split(":"); if (split.length > 0) { calendar.set(Calendar.HOUR_OF_DAY, Integer.parseInt(split[0])); }/*www . ja v a 2 s .c o m*/ if (split.length > 1) { calendar.set(Calendar.MINUTE, Integer.parseInt(split[1])); } if (split.length > 2) { calendar.set(Calendar.SECOND, Integer.parseInt(split[2])); } return calendar; }
From source file:Main.java
public static void moveToCalendarMinute(Calendar cal, int minute) { assertArgumentNotMinusInteger("minute", minute); cal.set(Calendar.MINUTE, minute); }
From source file:Main.java
public static void moveToCalendarSecond(Calendar cal, int second) { assertArgumentNotMinusInteger("second", second); cal.set(Calendar.SECOND, second); }
From source file:Main.java
private static void setEndOfWeekToCalendar(Calendar c) { // Get First Day of next week so it will be considered until 0 hrs of // next week//from w ww . j av a 2 s.c om c.set(Calendar.DAY_OF_WEEK, c.getMaximum(Calendar.DAY_OF_WEEK)); setEndOfDayToCalendar(c); Log.d("La Cuenta: ", "Max of Current Week: " + DateFormat.getInstance().format(c.getTime())); }
From source file:Main.java
public static Date getFirstDayOfMonth(Date date) { if (date == null) { return null; }/*from ww w. ja v a 2 s . c om*/ Calendar calendar = Calendar.getInstance(Locale.getDefault()); calendar.setTime(date); calendar.set(Calendar.DAY_OF_MONTH, 1); return calendar.getTime(); }
From source file:Main.java
public static java.util.Date getDateStart(java.util.Date d) { Calendar c = new GregorianCalendar(); c.clear();//w w w . ja v a 2 s. c o m Calendar co = new GregorianCalendar(); co.setTime(d); c.set(Calendar.DAY_OF_MONTH, co.get(Calendar.DAY_OF_MONTH)); c.set(Calendar.MONTH, co.get(Calendar.MONTH)); c.set(Calendar.YEAR, co.get(Calendar.YEAR)); // c.add(Calendar.DAY_OF_MONTH,1); // c.add(Calendar.MILLISECOND,-1); return c.getTime(); }
From source file:Main.java
public static Date getDateTimeFrom(int hour, int minute) { Calendar calendar = Calendar.getInstance(); calendar.set(Calendar.DAY_OF_MONTH, 0); calendar.set(Calendar.MONTH, 0); calendar.set(Calendar.YEAR, 0); calendar.set(Calendar.MINUTE, minute); calendar.set(Calendar.HOUR_OF_DAY, hour); calendar.set(Calendar.SECOND, 0); calendar.set(Calendar.MILLISECOND, 0); Date ret = calendar.getTime(); return ret;//from ww w . jav a 2s .c o m }
From source file:Main.java
public static Date getDateTimeFrom(int year, int monthOfYear, int dayOfMonth) { Calendar calendar = Calendar.getInstance(); calendar.set(Calendar.DAY_OF_MONTH, dayOfMonth); calendar.set(Calendar.MONTH, monthOfYear - 1); calendar.set(Calendar.YEAR, year); calendar.set(Calendar.MINUTE, 0); calendar.set(Calendar.HOUR_OF_DAY, 0); calendar.set(Calendar.SECOND, 0); calendar.set(Calendar.MILLISECOND, 0); Date ret = calendar.getTime(); return ret;//ww w . j av a2 s . co m }
From source file:Main.java
/** * @param startDateTime//from w ww .j a va 2 s. co m * @param endDateTime * @return the difference in hours between the second timestamp and first */ public static double getDifferenceInHours(Timestamp startDateTime, Timestamp endDateTime) { int difference = 0; Calendar startCalendar = Calendar.getInstance(); startCalendar.setTime(startDateTime); Calendar endCalendar = Calendar.getInstance(); endCalendar.setTime(endDateTime); // First, get difference in whole days Calendar startCompare = Calendar.getInstance(); startCompare.setTime(startDateTime); startCompare.set(Calendar.HOUR_OF_DAY, 0); startCompare.set(Calendar.MINUTE, 0); Calendar endCompare = Calendar.getInstance(); endCompare.setTime(endDateTime); endCompare.set(Calendar.HOUR_OF_DAY, 0); endCompare.set(Calendar.MINUTE, 0); return (endCalendar.getTimeInMillis() - startCalendar.getTimeInMillis()) / (60.0000 * 60.0000 * 1000.0000); }