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:edu.stanford.muse.email.CalendarUtil.java
public static int getDiffInMonths(Date firstDate, Date lastDate) { Calendar cFirst = new GregorianCalendar(); cFirst.setTime(firstDate);/* ww w .j a v a 2s . c om*/ Calendar cLast = new GregorianCalendar(); cLast.setTime(lastDate); int cFirst_year = cFirst.get(Calendar.YEAR); int cFirst_month = cFirst.get(Calendar.MONTH); int cLast_year = cLast.get(Calendar.YEAR); int cLast_month = cLast.get(Calendar.MONTH); return (cLast_year - cFirst_year) * (cLast.getMaximum(Calendar.MONTH) - cLast.getMinimum(Calendar.MONTH) + 1) + (cLast_month - cFirst_month); }
From source file:eu.trentorise.smartcampus.mobility.processor.alerts.ParkingChecker.java
private static String buildDate() { Calendar cal = new GregorianCalendar(); return cal.get(Calendar.DAY_OF_MONTH) + "-" + cal.get(Calendar.MONTH) + "-" + cal.get(Calendar.YEAR); }
From source file:com.microsoft.exchange.DateHelp.java
/** * // w ww . ja v a2 s . c om * @param date * @return */ public static XMLGregorianCalendar convertDateToXMLGregorianCalendar(final Date date) { if (date == null) { return null; } 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:com.autentia.common.util.DateFormater.java
public static Date normalizeInitDate(Date date) { GregorianCalendar gCalendar = new GregorianCalendar(); gCalendar.setTime(date);//from w ww. j a v a2 s. com gCalendar.set(Calendar.HOUR_OF_DAY, 0); gCalendar.set(Calendar.MINUTE, 0); gCalendar.set(Calendar.SECOND, 0); gCalendar.set(Calendar.MILLISECOND, 0); return gCalendar.getTime(); }
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); }
From source file:com.tdclighthouse.prototype.utils.TdcUtils.java
public static String getExpiresDate(int hours) { GregorianCalendar calendar = new GregorianCalendar(); calendar.add(Calendar.HOUR, hours); Date date = calendar.getTime(); return dateToRFC1123(date); }
From source file:org.grails.datastore.mapping.model.types.BasicTypeConverterRegistrar.java
public void register(ConverterRegistry registry) { registry.addConverter(new Converter<Date, String>() { public String convert(Date date) { return String.valueOf(date.getTime()); }// w w w . j a va 2 s . c o m }); registry.addConverter(new Converter<Date, Calendar>() { public Calendar convert(Date date) { final GregorianCalendar calendar = new GregorianCalendar(); calendar.setTime(date); return calendar; } }); registry.addConverter(new Converter<Integer, Long>() { public Long convert(Integer integer) { return integer.longValue(); } }); registry.addConverter(new Converter<Long, Integer>() { public Integer convert(Long longValue) { return longValue.intValue(); } }); registry.addConverter(new Converter<Integer, Double>() { public Double convert(Integer integer) { return integer.doubleValue(); } }); registry.addConverter(new Converter<CharSequence, Date>() { public Date convert(CharSequence s) { try { final Long time = Long.valueOf(s.toString()); return new Date(time); } catch (NumberFormatException e) { throw new IllegalArgumentException(e); } } }); registry.addConverter(new Converter<CharSequence, Double>() { public Double convert(CharSequence s) { try { return Double.valueOf(s.toString()); } catch (NumberFormatException e) { throw new IllegalArgumentException(e); } } }); registry.addConverter(new Converter<CharSequence, Integer>() { public Integer convert(CharSequence s) { try { return Integer.valueOf(s.toString()); } catch (NumberFormatException e) { throw new IllegalArgumentException(e); } } }); registry.addConverter(new Converter<CharSequence, Long>() { public Long convert(CharSequence s) { try { return Long.valueOf(s.toString()); } catch (NumberFormatException e) { throw new IllegalArgumentException(e); } } }); registry.addConverter(new Converter<Object, String>() { public String convert(Object o) { return o.toString(); } }); registry.addConverter(new Converter<Calendar, String>() { public String convert(Calendar calendar) { return String.valueOf(calendar.getTime().getTime()); } }); registry.addConverter(new Converter<CharSequence, Calendar>() { public Calendar convert(CharSequence s) { try { Date date = new Date(Long.valueOf(s.toString())); Calendar c = new GregorianCalendar(); c.setTime(date); return c; } catch (NumberFormatException e) { throw new IllegalArgumentException(e); } } }); }
From source file:com.mycollab.aspect.InjectTimeLoggingAspect.java
@Before("execution(public * com.mycollab..service..*.saveWithSession(..)) && args(bean, username)") public void injectDateForSaveMethod(JoinPoint joinPoint, Object bean, String username) { try {/* w w w.ja v a 2 s.c om*/ LOG.debug("Set createtime and lastupdatedtime if enable"); PropertyUtils.setProperty(bean, "createdtime", new GregorianCalendar().getTime()); PropertyUtils.setProperty(bean, "lastupdatedtime", new GregorianCalendar().getTime()); } catch (Exception e) { } }
From source file:Main.java
/** * This method converts from GMT to local timezone * /*from ww w . j a v a 2 s . co m*/ * @param date * date in GMT timezone * @return the date in local timezone */ public static Date offsetDateFromGMT(final Date date) { // Create a calendar - it will default to the current OS timezone. final GregorianCalendar gc = new GregorianCalendar(); // Calculate the total offset from GMT final int totalOffset = gc.get(Calendar.ZONE_OFFSET) + gc.get(Calendar.DST_OFFSET); // Calculate the time in GMT final long localTime = date.getTime() + totalOffset; // Create a date using the calculated GMT time final Date localDate = new Date(localTime); return localDate; }
From source file:com.github.jgility.core.planning.AbstractPlan.java
/** * Instanziiert ein Objekt der abstrakten Klasse {@link AbstractPlan}. Der Startwert is das * aktuelle {@link Calendar}-Objekt. Das Ende ist auf 14-Tage datiert. *///w w w . j a va 2 s. com public AbstractPlan() { Calendar calStart = new GregorianCalendar(); Calendar calEnd = new GregorianCalendar(); calEnd.add(Calendar.DATE, 14); start = calStart; end = calEnd; }