List of usage examples for java.util GregorianCalendar GregorianCalendar
public GregorianCalendar()
GregorianCalendar
using the current time in the default time zone with the default Locale.Category#FORMAT FORMAT locale. From source file:Main.java
/** * Convert the {@link Date} into a {@link XMLGregorianCalendar}. * //from w ww . j a v a2s . co m * Calls {@link DatatypeFactory#newInstance()} - if a {@link DatatypeConfigurationException} * is thrown it get's wrapped in the unchecked {@link IllegalStateException}. * * @param date * @return the converted calendar * @throws IllegalStateException wrapping a {@link DatatypeConfigurationException}. */ public static XMLGregorianCalendar convertDateToXMLGregorianCalendar(final Date date) { GregorianCalendar calendar = new GregorianCalendar(); calendar.setTime(date); try { return DatatypeFactory.newInstance().newXMLGregorianCalendar(calendar); } catch (DatatypeConfigurationException e) { throw new IllegalStateException("unable to invoke DatatypeFactory.newInstance", e); } }
From source file:DateUtils.java
public static final String formatDate(Date dt, String format) { GregorianCalendar cal = new GregorianCalendar(); cal.setTime(dt);/*from w w w .ja va2 s .co m*/ java.text.SimpleDateFormat sdf = new java.text.SimpleDateFormat(format); sdf.setTimeZone(TimeZone.getDefault()); return (sdf.format(cal.getTime())); }
From source file:Main.java
private static Date calculate(Date d, int field, int amount) { if (d == null) return null; GregorianCalendar g = new GregorianCalendar(); g.setGregorianChange(d);/*from ww w.j a v a2 s . c o m*/ g.add(field, amount); return g.getTime(); }
From source file:io.github.seiferma.jameica.hibiscus.dkb.creditcard.util.DateUtils.java
public static Date getCurrentDate() { return new GregorianCalendar().getTime(); }
From source file:TimeUtil.java
public static String monthStringFormat(long msecs) { GregorianCalendar cal = new GregorianCalendar(); cal.setTime(new Date(msecs)); return monthStringFormat(cal.get(Calendar.MONTH)); }
From source file:com.saax.gestorweb.util.DAOAleatorio.java
public static Date getDataByOffset(int offsetDataAtual, boolean up) { GregorianCalendar gc = new GregorianCalendar(); Date hoje = DateUtils.truncate(new Date(), Calendar.DATE); gc.setTime(hoje); // hoje truncando as horas for (int i = 0; i < offsetDataAtual; i++) { gc.roll(GregorianCalendar.DAY_OF_MONTH, up); if (gc.getActualMaximum(GregorianCalendar.DAY_OF_MONTH) == gc.get(GregorianCalendar.DAY_OF_MONTH)) { gc.roll(GregorianCalendar.MONTH, up); }/*from w w w . j a v a2s. co m*/ } return DateUtils.truncate(new Date(gc.getTimeInMillis()), Calendar.DATE); }
From source file:TimeUtil.java
public static String stringSecsFormat(long msecs) { GregorianCalendar cal = new GregorianCalendar(); StringBuffer sBuf = new StringBuffer(11); cal.setTime(new Date(msecs)); int hour = cal.get(Calendar.HOUR); if (hour == 0) hour = 12;/*ww w . j av a 2 s.c om*/ if (hour < 10) sBuf.append(" "); sBuf.append(Integer.toString(hour)); sBuf.append(":"); int minute = cal.get(Calendar.MINUTE); if (minute < 10) sBuf.append("0"); sBuf.append(Integer.toString(minute)); sBuf.append(":"); int secs = cal.get(Calendar.SECOND); if (secs < 10) { sBuf.append("0"); } sBuf.append(Integer.toString(secs)); sBuf.append(" "); sBuf.append(cal.get(Calendar.AM_PM) == Calendar.AM ? "AM" : "PM"); return (sBuf.toString()); }
From source file:com.pureinfo.force.util.TimerUtil.java
private static Calendar getTimeToday(Calendar _today, String _sTime) { Calendar todayTime = new GregorianCalendar(); try {//from www. ja va 2 s.co m todayTime.setTime(TIME_FORMAT.parse(_sTime)); } catch (ParseException ex) { throw new PureRuntimeException(PureException.INVALID_REQUEST, "time must be HH:mm TIME_FORMAT", ex); } todayTime.set(Calendar.YEAR, _today.get(Calendar.YEAR)); todayTime.set(Calendar.MONTH, _today.get(Calendar.MONTH)); todayTime.set(Calendar.DAY_OF_MONTH, _today.get(Calendar.DAY_OF_MONTH)); return todayTime; }
From source file:ezbake.services.provenance.graph.Utils.java
public static ezbake.base.thrift.DateTime convertDate2DateTime(final java.util.Date theDate) { final Calendar cal = new GregorianCalendar(); cal.setTime(theDate);/*w w w. j a va2 s .c o m*/ // get calendar parts final int year = cal.get(Calendar.YEAR); final int month = cal.get(Calendar.MONTH) + 1; final int day = cal.get(Calendar.DAY_OF_MONTH); final int hour = cal.get(Calendar.HOUR_OF_DAY); final int minute = cal.get(Calendar.MINUTE); final int second = cal.get(Calendar.SECOND); int offsetMinutes = (cal.getTimeZone().getOffset(cal.getTimeInMillis())) / (1000 * 60); // set thrift DateTime propertiesd final ezbake.base.thrift.DateTime dt = new ezbake.base.thrift.DateTime(); // Date final ezbake.base.thrift.Date date = new ezbake.base.thrift.Date(); date.setMonth((short) month).setDay((short) day).setYear((short) year); dt.setDate(date); // Time with TimeZone final ezbake.base.thrift.Time t = new ezbake.base.thrift.Time(); boolean afterUtc = offsetMinutes > 0; offsetMinutes = Math.abs(offsetMinutes); final ezbake.base.thrift.TimeZone tz = new ezbake.base.thrift.TimeZone((short) (offsetMinutes / 60), (short) (offsetMinutes % 60), afterUtc); t.setHour((short) hour).setMinute((short) minute).setSecond((short) second).setTz(tz); dt.setTime(t); return dt; }
From source file:io.github.seiferma.jameica.hibiscus.dkb.creditcard.util.DateUtils.java
public static Date getDateAgo(Unit unit, int amount) { Validate.inclusiveBetween(0, Integer.MAX_VALUE, amount); Calendar calendar = new GregorianCalendar(); calendar.add(unit.getCalendarField(), -amount); return calendar.getTime(); }