List of usage examples for java.util GregorianCalendar setTimeInMillis
public void setTimeInMillis(long millis)
From source file:com.evolveum.midpoint.prism.xml.XmlTypeConverter.java
public static XMLGregorianCalendar createXMLGregorianCalendar(long timeInMillis) { GregorianCalendar gregorianCalendar = new GregorianCalendar(); gregorianCalendar.setTimeInMillis(timeInMillis); return createXMLGregorianCalendar(gregorianCalendar); }
From source file:org.oscarehr.common.hl7.v2.oscar_to_oscar.DataTypeUtils.java
private static GregorianCalendar getCalendarFromDT(DT dt) throws DataTypeException { // hl7/hapi returns 0 for no date if (dt.getYear() == 0 || dt.getMonth() == 0 || dt.getDay() == 0) return (null); GregorianCalendar cal = new GregorianCalendar(); // zero out fields we don't use cal.setTimeInMillis(0); cal.set(GregorianCalendar.YEAR, dt.getYear()); cal.set(GregorianCalendar.MONTH, dt.getMonth() - 1); cal.set(GregorianCalendar.DAY_OF_MONTH, dt.getDay()); // force materialisation of values cal.getTimeInMillis();//from w w w . j a v a 2s . c o m return (cal); }
From source file:org.oscarehr.common.hl7.v2.oscar_to_oscar.DataTypeUtils.java
public static GregorianCalendar getCalendarFromDTM(DTM dtm) throws DataTypeException { // hl7/hapi returns 0 for no date if (dtm.getYear() == 0 || dtm.getMonth() == 0 || dtm.getDay() == 0) return (null); GregorianCalendar cal = new GregorianCalendar(); // zero out fields we don't use cal.setTimeInMillis(0); cal.set(GregorianCalendar.YEAR, dtm.getYear()); cal.set(GregorianCalendar.MONTH, dtm.getMonth() - 1); cal.set(GregorianCalendar.DAY_OF_MONTH, dtm.getDay()); cal.set(GregorianCalendar.HOUR_OF_DAY, dtm.getHour()); cal.set(GregorianCalendar.MINUTE, dtm.getMinute()); cal.set(GregorianCalendar.SECOND, dtm.getSecond()); // force materialisation of values cal.getTimeInMillis();//from ww w . j a va 2s . c o m return (cal); }
From source file:org.yawlfoundation.yawl.util.StringUtil.java
public static String longToDateTime(long time) { GregorianCalendar gregCal = new GregorianCalendar(); gregCal.setTimeInMillis(time); try {/*w ww . j av a 2 s. c o m*/ XMLGregorianCalendar cal = DatatypeFactory.newInstance().newXMLGregorianCalendar(gregCal); return cal.toXMLFormat(); } catch (DatatypeConfigurationException dce) { return null; } }
From source file:org.apache.ranger.audit.provider.MiscUtil.java
public static Date getUTCDateForLocalDate(Date date) { TimeZone gmtTimeZone = TimeZone.getTimeZone("GMT+0"); Calendar local = Calendar.getInstance(); int offset = local.getTimeZone().getOffset(local.getTimeInMillis()); GregorianCalendar utc = new GregorianCalendar(gmtTimeZone); utc.setTimeInMillis(date.getTime()); utc.add(Calendar.MILLISECOND, -offset); return utc.getTime(); }
From source file:org.apache.ranger.audit.provider.MiscUtil.java
public static Date getUTCDate() { TimeZone gmtTimeZone = TimeZone.getTimeZone("GMT+0"); Calendar local = Calendar.getInstance(); int offset = local.getTimeZone().getOffset(local.getTimeInMillis()); GregorianCalendar utc = new GregorianCalendar(gmtTimeZone); utc.setTimeInMillis(local.getTimeInMillis()); utc.add(Calendar.MILLISECOND, -offset); return utc.getTime(); }
From source file:hu.unideb.inf.rdfizers.rpm.ModelBuilder.java
/** * Converts a POSIX time value to a W3C XML Schema <a href="http://www.w3.org/TR/xmlschema-2/#dateTime">dateTime</a> value. * * @param seconds/*from www . j a va 2 s. c om*/ * @return */ private static XMLGregorianCalendar toDateTime(int seconds) { GregorianCalendar cal = new GregorianCalendar(); cal.setTimeInMillis(seconds * 1000L); try { return DatatypeFactory.newInstance().newXMLGregorianCalendar(cal); } catch (DatatypeConfigurationException e) { return null; } }
From source file:com.alkacon.opencms.calendar.CmsSerialDateWidget.java
/** * Returns the given timestamp as String formatted in a localized pattern.<p> * /*from w w w .j a v a 2 s. c om*/ * @param locale the locale for the time format * @param messages the messages that contain the time format definitions * @param timestamp the time to format * @param showDate flag to show the date in the formatted String * @param showTime flag to show the time in the formatted String * * @return the given timestamp as String formatted in a localized pattern */ public static String getCalendarLocalizedTime(Locale locale, CmsMessages messages, long timestamp, boolean showDate, boolean showTime) { // get the current date & time TimeZone zone = TimeZone.getDefault(); GregorianCalendar cal = new GregorianCalendar(zone, locale); cal.setTimeInMillis(timestamp); String datePattern = ""; if (showDate) { datePattern = messages.key(org.opencms.workplace.Messages.GUI_CALENDAR_DATE_FORMAT_0); if (showTime) { datePattern += " "; } } if (showTime) { datePattern += messages.key(org.opencms.workplace.Messages.GUI_CALENDAR_TIME_FORMAT_0); } // format it nicely according to the localized pattern DateFormat df = new SimpleDateFormat(CmsCalendarWidget.getCalendarJavaDateFormat(datePattern)); return df.format(cal.getTime()); }
From source file:de.sindzinski.wetter.util.Utility.java
@SuppressLint("StringFormatMatches") public static String getHourlyDayString(Context context, long timeInMillis, String timeZoneId) { // The day string for forecast uses the following logic: // For today: "Today, June 8" // For tomorrow: "Tomorrow" // For the next 5 days: "Wednesday // " (just the day name) // For all days after that: "Mon Jun 8" TimeZone timeZone;// w w w.j ava 2 s . co m if (timeZoneId.equals("")) { timeZone = TimeZone.getDefault(); } else { timeZone = TimeZone.getTimeZone(timeZoneId); } GregorianCalendar gregorianCalendar = new GregorianCalendar(timeZone); gregorianCalendar.setTimeInMillis(timeInMillis); int day = gregorianCalendar.get(Calendar.DAY_OF_MONTH); //code for formatting the date Calendar calendar = Calendar.getInstance(); int today = calendar.get(Calendar.DAY_OF_MONTH); Date time = gregorianCalendar.getTime(); // SimpleDateFormat shortDateFormat = new SimpleDateFormat("EEE MMM dd HH:MM"); // shortDateFormat.setTimeZone(timeZone); try { if (day < today + 1) { // If the input date is less than a week in the future, just return the day name. SimpleDateFormat shortDateFormat = new SimpleDateFormat("HH:00"); shortDateFormat.setTimeZone(timeZone); String dsorig = shortDateFormat.format(timeInMillis); Date dconv = shortDateFormat.parse(dsorig); String sconv = shortDateFormat.format(dconv); return sconv; } else { // Otherwise, use the form "Mon Jun 3" SimpleDateFormat shortDateFormat = new SimpleDateFormat("EEE HH:00"); shortDateFormat.setTimeZone(timeZone); String dsorig = shortDateFormat.format(timeInMillis); Date dconv = shortDateFormat.parse(dsorig); String sconv = shortDateFormat.format(dconv); return sconv; } } catch (Exception e) { e.printStackTrace(); return ""; } }
From source file:org.wiredwidgets.cow.server.convert.DateToXMLGregorianCalendar.java
@Override public XMLGregorianCalendar convert(Date source) { GregorianCalendar gcal = new GregorianCalendar(); gcal.setTimeInMillis(source.getTime()); return dtf.newXMLGregorianCalendar(gcal); }