List of usage examples for java.util Calendar set
public void set(int field, int value)
From source file:org.openmrs.module.patientportaltoolkit.api.db.hibernate.HibernateReminderDAO.java
public static Date clearDate(Date dateTime) { if (dateTime == null) { return null; }// w ww .j a v a 2s. c om Calendar cal = Calendar.getInstance(); cal.setTime(dateTime); cal.set(Calendar.HOUR_OF_DAY, 0); cal.set(Calendar.MINUTE, 0); cal.set(Calendar.SECOND, 0); cal.set(Calendar.MILLISECOND, 0); Date dateWithoutTime = cal.getTime(); return dateWithoutTime; }
From source file:at.florian_lentsch.expirysync.NotifyChecker.java
private static long getFirstStartMillis(Context appContext) { final SharedPreferences sharedPref = appContext.getSharedPreferences("main", Context.MODE_PRIVATE); long firstStartMillis = sharedPref.getLong(SettingsActivity.KEY_ALERT_TIME, -1); if (firstStartMillis == -1) { return -1; }//from w ww. ja v a 2 s . co m Calendar midnight = Calendar.getInstance(TimeZone.getTimeZone("UTC")); midnight.set(Calendar.HOUR_OF_DAY, 0); midnight.set(Calendar.MINUTE, 0); midnight.set(Calendar.SECOND, 0); midnight.set(Calendar.MILLISECOND, 0); // add "today at 0:00" to the ms value for the alarm (else the alarm // would be scheduled for 1970-01-01): firstStartMillis += midnight.getTimeInMillis(); // if we're already past the alarm time today, we need to add another // day: if (firstStartMillis <= Calendar.getInstance().getTimeInMillis()) { firstStartMillis += AlarmManager.INTERVAL_DAY; } return firstStartMillis; }
From source file:com.sun.japex.report.ChartGenerator.java
/** * Compare two calendar instances from test suite reports ignoring * the time of the day./*from w ww . j ava2 s. com*/ */ static protected boolean onSameDate(TestSuiteReport r1, TestSuiteReport r2) { Calendar cc1 = (Calendar) r1.getDate().clone(); cc1.set(HOUR_OF_DAY, 0); cc1.set(MINUTE, 0); cc1.set(SECOND, 0); Calendar cc2 = (Calendar) r2.getDate().clone(); cc2.set(HOUR_OF_DAY, 0); cc2.set(MINUTE, 0); cc2.set(SECOND, 0); return cc1.equals(cc2); }
From source file:Main.java
private static Date getEasterDay(int year) { int a = year % 19; int b = year / 100; int c = year % 100; int d = b / 4; int e = b % 4; int f = (b + 8) / 25; int g = (b - f + 1) / 3; int h = ((19 * a) + b - d - g + 15) % 30; int i = c / 4; int k = c % 4; int l = (32 + (2 * e) + (2 * i) - h - k) % 7; int m = (a + (11 * h) + (22 * l)) / 451; int n = (h + l - (7 * m) + 114) / 31; // This is the month number. int p = (h + l - (7 * m) + 114) % 31; // This is the date minus one. Calendar cal = Calendar.getInstance(); cal.set(Calendar.YEAR, year); cal.set(Calendar.MONTH, n - 1); cal.set(Calendar.DATE, p + 1); return cal.getTime(); }
From source file:com.ocs.dynamo.utils.DateUtils.java
/** * Truncates a calendar object, setting all time fields to zero * /*from w w w . j a v a2 s . c o m*/ * @param calendar * @return */ public static Calendar truncate(Calendar calendar) { calendar.set(Calendar.HOUR_OF_DAY, 0); calendar.set(Calendar.MINUTE, 0); calendar.set(Calendar.SECOND, 0); calendar.set(Calendar.MILLISECOND, 0); return calendar; }
From source file:Main.java
public static Date parseData(String text) { Calendar calendar = Calendar.getInstance(); if (text.contains(":")) { String[] time = text.split(":"); int hours = Integer.parseInt(time[0]); calendar.set(Calendar.MINUTE, Integer.parseInt(time[1])); calendar.set(Calendar.HOUR_OF_DAY, hours); return calendar.getTime(); } else if (text.contains("/")) { String[] date = text.split("/"); if (date.length == 3) { calendar.set(Calendar.DAY_OF_MONTH, Integer.parseInt(date[0])); calendar.set(Calendar.MONTH, Integer.parseInt(date[1]) - 1); calendar.set(Calendar.YEAR, Integer.parseInt(date[2])); calendar.set(Calendar.MINUTE, 0); calendar.set(Calendar.HOUR_OF_DAY, 0); return calendar.getTime(); } else if (date.length == 2) { calendar.set(Calendar.DAY_OF_MONTH, Integer.parseInt(date[0])); calendar.set(Calendar.MONTH, Integer.parseInt(date[1]) - 1); calendar.set(Calendar.MINUTE, 0); calendar.set(Calendar.HOUR_OF_DAY, 0); return calendar.getTime(); }/*w w w. j a v a 2 s . co m*/ } return null; }