List of usage examples for java.util Calendar setTimeInMillis
public void setTimeInMillis(long millis)
From source file:com.github.daddo.validation.validator.Util.java
static Calendar safeCastToCalendar(Object object) { if (object == null) return null; if (object instanceof Calendar) return (Calendar) object; if (object instanceof Date) { Calendar result = Calendar.getInstance(); result.setTime((Date) object); return result; }/* www.ja va2 s . c o m*/ if (object instanceof Number) { Calendar result = Calendar.getInstance(); result.setTimeInMillis(((Number) object).longValue()); return result; } throw new UnexpectedTypeException(object.getClass(), Calendar.class, Date.class, Number.class); }
From source file:jp.primecloud.auto.api.ListEventLog.java
private static Date getFromCurrentDate(String fromCurrent) { Calendar calendar = Calendar.getInstance(); calendar.setTimeInMillis(System.currentTimeMillis()); if (fromCurrent.endsWith("d")) { int date = Integer.parseInt(fromCurrent.split("d")[0]); calendar.set(Calendar.DATE, calendar.get(Calendar.DATE) - date); } else if (fromCurrent.endsWith("H")) { int hour = Integer.parseInt(fromCurrent.split("H")[0]); calendar.set(Calendar.HOUR_OF_DAY, calendar.get(Calendar.HOUR_OF_DAY) - hour); } else if (fromCurrent.endsWith("m")) { int minute = Integer.parseInt(fromCurrent.split("m")[0]); calendar.set(Calendar.MINUTE, calendar.get(Calendar.MINUTE) - minute); }/*from w ww .jav a 2s . c om*/ return calendar.getTime(); }
From source file:alfio.datamapper.QueryType.java
private static SqlParameterSource extractParameters(Method m, Object[] args) { Annotation[][] parameterAnnotations = m.getParameterAnnotations(); if (parameterAnnotations == null || parameterAnnotations.length == 0) { return new EmptySqlParameterSource(); }//from w ww . ja v a 2 s .c o m MapSqlParameterSource ps = new MapSqlParameterSource(); Class<?>[] parameterTypes = m.getParameterTypes(); for (int i = 0; i < args.length; i++) { String name = parameterName(parameterAnnotations[i]); if (name != null) { if (args[i] != null && ZonedDateTime.class.isAssignableFrom(parameterTypes[i])) { ZonedDateTime dateTime = ZonedDateTime.class.cast(args[i]); final ZonedDateTime utc = dateTime.withZoneSameInstant(ZoneId.of("UTC")); Calendar c = Calendar.getInstance(); c.setTimeZone(TimeZone.getTimeZone("UTC")); c.setTimeInMillis(utc.toInstant().toEpochMilli()); ps.addValue(name, c, Types.TIMESTAMP); } else { ps.addValue(name, args[i], StatementCreatorUtils.javaTypeToSqlParameterType(parameterTypes[i])); } } } return ps; }
From source file:helper.util.DateHelper.java
public static CalendarRange getRangeHoursBeforeNow(TimeZone tz, int hours) { Calendar start = Calendar.getInstance(tz); Calendar end = Calendar.getInstance(tz); start.setTimeInMillis(end.getTimeInMillis()); start.add(Calendar.HOUR_OF_DAY, -hours); //fix for BST range issue on check (first dock issue). // BST is not observed so jst roll forward here) // also allows for normal variations in timestamp (will still include last one if +n minutes) end.add(Calendar.HOUR_OF_DAY, 24); return new CalendarRange(start, end); }
From source file:de.blizzy.backup.BackupApplication.java
static void scheduleBackupRun(boolean forceRunNow) { if (timer != null) { if (backupTimerTask != null) { backupTimerTask.cancel();//from ww w . j a v a2 s. co m backupTimerTask = null; } backupTimerTask = new TimerTask() { @Override public void run() { runBackup(); } }; if (forceRunNow) { timer.schedule(backupTimerTask, 0); } else { IDialogSettings backupSection = Utils.getSection("backup"); //$NON-NLS-1$ long lastRun = backupSection.getLong("lastRun"); //$NON-NLS-1$ Settings settings = settingsManager.getSettings(); if (settings.isRunHourly()) { nextBackupRunTime = lastRun; } else { Calendar c = Calendar.getInstance(); c.setTimeInMillis(lastRun); c.set(Calendar.HOUR_OF_DAY, settings.getDailyHours()); c.set(Calendar.MINUTE, settings.getDailyMinutes()); nextBackupRunTime = c.getTimeInMillis(); } long now = System.currentTimeMillis(); for (;;) { nextBackupRunTime = clearSeconds(nextBackupRunTime); if (nextBackupRunTime > now) { break; } nextBackupRunTime += settings.isRunHourly() ? 60L * 60L * 1000L : 24L * 60L * 60L * 1000L; } timer.schedule(backupTimerTask, Math.max(nextBackupRunTime - now, 0)); } } }
From source file:jp.classmethod.aws.brian.job.BrianQuartzJobBean.java
static SimpleDateFormat createFormat() { SimpleDateFormat format = new SimpleDateFormat(DATE_FORMAT); Calendar calendar = Calendar.getInstance(TimeZone.getTimeZone("Japan")); // TODO localize calendar.setMinimalDaysInFirstWeek(4); calendar.setFirstDayOfWeek(Calendar.MONDAY); calendar.setTimeInMillis(0); format.setCalendar(calendar);/*from ww w . j av a 2s.com*/ return format; }
From source file:com.projity.util.DateTime.java
public static long closestDate(long date) { Calendar cal = DateTime.calendarInstance(); cal.setTimeInMillis(date); // cal.set(Calendar.SECOND,0); // now going to seconds cal.set(Calendar.MILLISECOND, 0); return cal.getTimeInMillis(); }
From source file:com.projity.util.DateTime.java
public static long minuteFloor(long date) { Calendar cal = DateTime.calendarInstance(); cal.setTimeInMillis(date); cal.set(Calendar.MILLISECOND, 0); cal.set(Calendar.SECOND, 0);// w w w . j ava 2s. c o m return cal.getTimeInMillis(); }
From source file:com.projity.util.DateTime.java
public static long hourFloor(long date) { Calendar cal = DateTime.calendarInstance(); cal.setTimeInMillis(date); cal.set(Calendar.MINUTE, 0);/*from ww w. j a va 2 s . c om*/ cal.set(Calendar.SECOND, 0); cal.set(Calendar.MILLISECOND, 0); return cal.getTimeInMillis(); }
From source file:com.projity.util.DateTime.java
public static long dayFloor(long date) { Calendar cal = DateTime.calendarInstance(); cal.setTimeInMillis(date); cal.set(Calendar.MINUTE, 0);/*from w w w .j av a 2 s . co m*/ cal.set(Calendar.SECOND, 0); cal.set(Calendar.MILLISECOND, 0); cal.set(Calendar.HOUR_OF_DAY, 0); return cal.getTimeInMillis(); }