Example usage for java.util GregorianCalendar GregorianCalendar

List of usage examples for java.util GregorianCalendar GregorianCalendar

Introduction

In this page you can find the example usage for java.util GregorianCalendar GregorianCalendar.

Prototype

public GregorianCalendar() 

Source Link

Document

Constructs a default GregorianCalendar using the current time in the default time zone with the default Locale.Category#FORMAT FORMAT locale.

Usage

From source file:au.com.jwatmuff.eventmanager.model.misc.PoolChecker.java

public static int calculateAge(Date dob, Date censusDate) {
    if (dob == null)
        return -1;

    /* calculate age */
    GregorianCalendar birthCal = new GregorianCalendar();
    birthCal.setTime(dob);/*  w  ww.  j  a v  a  2s.  com*/
    int birthYear = birthCal.get(GregorianCalendar.YEAR);

    GregorianCalendar censusCal = new GregorianCalendar();
    censusCal.setTime(censusDate);
    int censusYear = censusCal.get(GregorianCalendar.YEAR);

    int age = censusYear - birthYear;

    birthCal.set(GregorianCalendar.YEAR, censusYear);
    if (censusCal.before(birthCal)) {
        age--;
    }

    return age;
}

From source file:com.sammyun.util.DateUtil.java

/**
 * _?yyyy/*from www.j ava2 s. c o m*/
 * 
 * @return int
 */
public static int getNextYear() {
    return new GregorianCalendar().get(Calendar.YEAR) + 1;
}

From source file:com.qpark.eip.core.spring.auth.LimitedAccessDataProvider.java

/**
 * Get a {@link Date}, where hours, minutes, seconds and milliseconds are
 * set to 0./*ww w .  j  a  v a2s . c o m*/
 *
 * @return the {@link Date} and the corresponding log string.
 */
private static SimpleEntry<Date, String> getRequestDate() {
    Calendar gc = new GregorianCalendar();
    gc.set(Calendar.HOUR_OF_DAY, 0);
    gc.set(Calendar.MINUTE, 0);
    gc.set(Calendar.SECOND, 0);
    gc.set(Calendar.MILLISECOND, 0);
    String hmss = String.format("%04d%02d%02d", gc.get(Calendar.YEAR), gc.get(Calendar.MONTH) + 1,
            gc.get(Calendar.DAY_OF_MONTH));
    SimpleEntry<Date, String> entry = new SimpleEntry<Date, String>(gc.getTime(), hmss);
    return entry;
}

From source file:example.users.webservice.persistence.mock.UsersMockDao.java

private void initUsers() {
    Calendar calendar = new GregorianCalendar();
    calendar.setLenient(false);//from  ww w . ja  v  a 2  s . c  o  m
    calendar.set(1984, 1, 23);
    try {
        User user1 = new User("Antonio", "Genovese", "Regist", calendar.getTime());
        calendar.set(1981, 6, 25);
        User user2 = new User("Gianluca", "Genovese", "Gianblues", calendar.getTime());
        calendar.set(2011, 7, 7);
        User user3 = new User("Gabriele", "Genovese", "Gaby", calendar.getTime());
        this.users.add(user1);
        this.users.add(user2);
        this.users.add(user3);
    } catch (IllegalArgumentException ex) {
        logger.error("Exception Calendar " + ex.getMessage());
    }

}

From source file:cput.codez.angorora.eventstar.services.Impl.LongEventsServiceImpl.java

@Override
public List<Event> getLongEvents() {
    List<Event> allEvents = new ArrayList<>();
    List<Event> longevents = new ArrayList<>();
    Calendar cal = new GregorianCalendar();
    allEvents = evRepo.findAll();/*from  w  w w.  j  av a 2  s. c o m*/
    for (Event allEv : allEvents) {
        if ((allEv.getEndDate().getTimeInMillis() - allEv.getStartDate().getTimeInMillis()) >= ms_in_day)
            longevents.add(allEv);
    }
    return longevents;
}

From source file:com.stgmastek.core.util.CommonUtils.java

/**
 * A new method, that contains the code previously present in the above
 * method, that is, to create an XML GC Object with both the Date and time
 * component.//from  www  .  jav  a 2 s  . co  m
 */
public static XMLGregorianCalendar getXMLDateTime(Date date) throws DatatypeConfigurationException {
    GregorianCalendar gCal = new GregorianCalendar();
    if (date != null) {
        gCal.setTime(date);
        XMLGregorianCalendar xgCal = DatatypeFactory.newInstance().newXMLGregorianCalendar(gCal);
        return xgCal;
    } else {
        return null;
    }
}

From source file:com.microsoft.exchange.DateHelper.java

/**
 * Convert the {@link Date} into a {@link XMLGregorianCalendar}.
 * /*from   w  w w  .  j  a  va 2s  . c  om*/
 * @param date
 * @return
 * @throws IllegalStateException wrapping a {@link DatatypeConfigurationException}.
 */
public static XMLGregorianCalendar convertDateToXMLGregorianCalendar(final Date date) {
    if (date == null) {
        return null;
    }
    GregorianCalendar calendar = new GregorianCalendar();
    calendar.setTime(date);
    return DATATYPE_FACTORY.newXMLGregorianCalendar(calendar);
}

From source file:Gestores.GestorUsuarios.java

public void registraUsuario(Restaurante restaurante) {
    Calendar cal = new GregorianCalendar();
    String fecha = cal.get(Calendar.YEAR) + "-" + (cal.get(Calendar.MONTH) + 1) + "-"
            + cal.get(Calendar.DAY_OF_MONTH);
    try {//from  w  w w . ja  v  a 2  s.co  m
        String query = "INSERT INTO restaurante (nombre, direccion, telefono, username, passwd, web, email, fecha) "
                + "VALUES (?,?,?,?,?,?,?,?)";
        jdbcTemplate.update(query,
                new Object[] { restaurante.getNombre(), restaurante.getDireccion(), restaurante.getTelefono(),
                        restaurante.getUsername(), gHash.md5(restaurante.getPassword()), restaurante.getWeb(),
                        restaurante.getEmail(), fecha });
    } catch (Exception e) {
        General.log("GestorUsuarios", "ERROR en registraUsuario: " + e.getMessage());
    }
}

From source file:com.hp.hpl.jena.sparql.util.Utils.java

public static String nowAsXSDDateTimeString() {
    return calendarToXSDDateTimeString(new GregorianCalendar());
}

From source file:WebCalendar.java

/** */
public WebCalendar() {
    m_gc = new GregorianCalendar();
    m_sdf = new SimpleDateFormat();
}