List of usage examples for java.util GregorianCalendar setTimeInMillis
public void setTimeInMillis(long millis)
From source file:org.apache.ranger.common.DateUtil.java
public static Date getUTCDate(long epoh) { if (epoh == 0) { return null; }/*from w w w. j a v a 2s. com*/ try { Calendar local = Calendar.getInstance(); int offset = local.getTimeZone().getOffset(epoh); GregorianCalendar utc = new GregorianCalendar(gmtTimeZone); utc.setTimeInMillis(epoh); utc.add(Calendar.MILLISECOND, -offset); return utc.getTime(); } catch (Exception ex) { return null; } }
From source file:Main.java
/** * Oftentimes all-day events have messed up starting times, which can cause * them to be displayed before events that happen in the previous day. * * The times are usually off by the Timezone offset, so we should be able * to just subtract the offset from the given event time, and it should be * all fixed./*from w w w .j a v a2 s. com*/ * * @param eventStart * @param eventEnd * The date to modify */ private static void fixAllDayEvent(GregorianCalendar eventStart, GregorianCalendar eventEnd) { long milliseconds = eventStart.getTimeInMillis(); milliseconds -= eventStart.getTimeZone().getRawOffset(); eventStart.setTimeInMillis(milliseconds); milliseconds = eventEnd.getTimeInMillis(); milliseconds -= eventEnd.getTimeZone().getRawOffset(); eventEnd.setTimeInMillis(milliseconds - 1000); }
From source file:org.orcid.utils.DateUtils.java
public static XMLGregorianCalendar convertToXMLGregorianCalendar(long time) { GregorianCalendar gregorianCalendar = new GregorianCalendar(); gregorianCalendar.setTimeInMillis(time); return createDataTypeFactory().newXMLGregorianCalendar(gregorianCalendar); }
From source file:org.onosproject.drivers.bti.Bti7000SnmpAlarmConsumer.java
/** * Converts an SNMP string representation into a {@link Date} object, * and applies time zone conversion to provide the time on the local machine, ie PSM server. * * @param actAlarmDateAndTime MIB-II DateAndTime formatted. May optionally contain * a timezone offset in 3 extra bytes * @param sysInfoTimeZone Must be supplied if actAlarmDateAndTime is just local time (with no timezone) * @param swVersion Must be supplied if actAlarmDateAndTime is just local time (with no timezone) * @return adjusted {@link Date} or a simple conversion if other fields are null. *//*from ww w . j av a2s . com*/ public static Date getLocalDateAndTime(String actAlarmDateAndTime, String sysInfoTimeZone, String swVersion) { if (StringUtils.isBlank(actAlarmDateAndTime)) { return null; } GregorianCalendar decodedDateAndTimeCal = btiMakeCalendar(OctetString.fromHexString(actAlarmDateAndTime)); if ((sysInfoTimeZone == null) || (swVersion == null)) { return decodedDateAndTimeCal.getTime(); } TimeZone javaTimeZone = getTimeZone(); decodedDateAndTimeCal.setTimeZone(javaTimeZone); GregorianCalendar localTime = new GregorianCalendar(); localTime.setTimeInMillis(decodedDateAndTimeCal.getTimeInMillis()); return localTime.getTime(); }
From source file:hudson.logging.LogRecorderManager.java
/** * Renders the given log recorders as RSS. *//* w w w . j ava2 s. co m*/ /*package*/ static void doRss(StaplerRequest req, StaplerResponse rsp, List<LogRecord> logs) throws IOException, ServletException { // filter log records based on the log level String level = req.getParameter("level"); if (level != null) { Level threshold = Level.parse(level); List<LogRecord> filtered = new ArrayList<LogRecord>(); for (LogRecord r : logs) { if (r.getLevel().intValue() >= threshold.intValue()) filtered.add(r); } logs = filtered; } RSS.forwardToRss("Hudson log", "", logs, new FeedAdapter<LogRecord>() { public String getEntryTitle(LogRecord entry) { return entry.getMessage(); } public String getEntryUrl(LogRecord entry) { return "log"; // TODO: one URL for one log entry? } public String getEntryID(LogRecord entry) { return String.valueOf(entry.getSequenceNumber()); } public String getEntryDescription(LogRecord entry) { return Functions.printLogRecord(entry); } public Calendar getEntryTimestamp(LogRecord entry) { GregorianCalendar cal = new GregorianCalendar(); cal.setTimeInMillis(entry.getMillis()); return cal; } public String getEntryAuthor(LogRecord entry) { return Mailer.descriptor().getAdminAddress(); } }, req, rsp); }
From source file:com.projity.util.DateTime.java
public static long midnightNextDay(long d) { d = dayFloor(d);/*from w w w . j a v a2s . co m*/ GregorianCalendar cal = calendarInstance(); cal.setTimeInMillis(d); cal.add(Calendar.DATE, 1); return cal.getTimeInMillis(); }
From source file:com.projity.util.DateTime.java
public static long nextDay(long day) { GregorianCalendar d = DateTime.calendarInstance(); d.setTimeInMillis(day); d.add(GregorianCalendar.DAY_OF_MONTH, 1); return d.getTimeInMillis(); }
From source file:com.projity.util.DateTime.java
public static long hour24() { GregorianCalendar cal = DateTime.calendarInstance(); cal.setTimeInMillis(0); cal.set(GregorianCalendar.HOUR_OF_DAY, 24); return cal.getTimeInMillis(); }
From source file:org.amanzi.neo.core.period.Period.java
/** * add one period/* w w w. j a v a 2 s . c o m*/ * * @param time - timestamp * @param period - period @see Calendar * @return timestamp+ 1 period */ private static Long addOnePeriod(final Long time, final int period) { final GregorianCalendar cl = new GregorianCalendar(); cl.setTimeInMillis(time); cl.add(period, 1); return cl.getTimeInMillis(); }
From source file:com.projity.util.DateTime.java
/** * Get an integer for the date in form YYYYMMDD where the months go from 1 to 12 (unlike calendar where they go from 0 to 11) * @param date//from w w w. ja va 2 s . co m * @return */ public static int toId(long date) { GregorianCalendar cal = DateTime.calendarInstance(); cal.setTimeInMillis(date); return cal.get(Calendar.YEAR) * 10000 + (1 + cal.get(Calendar.MONTH)) * 100 + cal.get(Calendar.DAY_OF_MONTH); }