Example usage for java.util Calendar YEAR

List of usage examples for java.util Calendar YEAR

Introduction

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

Prototype

int YEAR

To view the source code for java.util Calendar YEAR.

Click Source Link

Document

Field number for get and set indicating the year.

Usage

From source file:cvut.semestralka.validator.YearValidator.java

@Override
public void validate(FacesContext fc, UIComponent uic, Object o) throws ValidatorException {
    if (o == null || "".equals(o)) {
        return;//from   w w  w .  ja  va 2  s . c o m
    }

    Long l = Long.valueOf(String.valueOf(o));
    if (l < 1900) {
        throw new ValidatorException(
                new FacesMessage("Input value should be bigger then 1900", "the movie is too old."));
    }
    if (l > Calendar.getInstance().get(Calendar.YEAR)) {
        throw new ValidatorException(new FacesMessage("Input value should be less then Current Year",
                "Release year is bigger than this year"));
    }
}

From source file:com.pureinfo.force.util.TimerUtil.java

private static Calendar getTimeToday(Calendar _today, String _sTime) {
    Calendar todayTime = new GregorianCalendar();
    try {//www.java2 s.  c  om
        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:co.com.soinsoftware.altablero.controller.YearController.java

public String getLastYearString() {
    Calendar date = Calendar.getInstance();
    return String.valueOf(date.get(Calendar.YEAR) - 1);
}

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 {/*w  w  w.  java  2  s  .c  om*/
        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.sammyun.util.DateUtil.java

/**
 * ?//from w  w w  . java 2 s.co  m
 * 
 * @return int
 */
public static int getCurrYear() {
    return new GregorianCalendar().get(Calendar.YEAR);
}

From source file:Main.java

public static Calendar createCalendar(int year, int month, int dayOfMonth, int hour, int minute) {
    Calendar calendar = createCalendar(month, dayOfMonth, hour, minute);
    calendar.set(Calendar.YEAR, year);
    return calendar;
}

From source file:com.google.orkut.client.api.Util.java

static String getFormattedTimestamp(long timeMillis) {
    Calendar cal = Calendar.getInstance(TimeZone.getTimeZone(Constants.DateFormatter.UTC));
    cal.setTimeInMillis(timeMillis);// www . j  a v a2 s .  c om
    StringBuilder date = new StringBuilder();
    date.append(cal.get(Calendar.YEAR));
    date.append(Constants.DateFormatter.DATE_SEPARATOR);
    date.append(padSingleDigitNum(cal.get(Calendar.MONTH) + 1));
    date.append(Constants.DateFormatter.DATE_SEPARATOR);
    date.append(padSingleDigitNum(cal.get(Calendar.DATE)));
    date.append(Constants.DateFormatter.DATE_DELIM);
    date.append(padSingleDigitNum(cal.get(Calendar.HOUR)));
    date.append(Constants.DateFormatter.TIME_SEPARATOR);
    date.append(padSingleDigitNum(cal.get(Calendar.MINUTE)));
    date.append(Constants.DateFormatter.TIME_SEPARATOR);
    date.append(padSingleDigitNum(cal.get(Calendar.SECOND)));
    date.append(Constants.DateFormatter.TIME_DELIM);
    return date.toString();
}

From source file:com.clican.pluto.dataprocess.dpl.function.impl.Duration.java

public static double duration(Date d1, Date d2, String step) throws PrefixAndSuffixException {
    if (StringUtils.isEmpty(step) || step.equals("day")) {
        return (d1.getTime() - d2.getTime()) / (1000L * 3600 * 24);
    } else if (step.equals("month")) {
        Calendar c1 = Calendar.getInstance();
        c1.setTime(d1);//from   ww w  . ja  v a  2s.  c  om
        Calendar c2 = Calendar.getInstance();
        c2.setTime(d2);
        int month = (c1.get(Calendar.YEAR) - c2.get(Calendar.YEAR)) * 12
                + (c1.get(Calendar.MONTH) - c2.get(Calendar.MONTH));
        return month;
    } else {
        throw new PrefixAndSuffixException("??");
    }
}

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.//  w w w.j a v  a 2  s.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:com.livinglogic.ul4.FunctionAsJSON.java

private static void call(StringBuilder builder, Object obj) {
    if (obj == null)
        builder.append("null");
    else if (obj instanceof Boolean)
        builder.append(((Boolean) obj).booleanValue() ? "true" : "false");
    else if (obj instanceof Integer || obj instanceof Byte || obj instanceof Short || obj instanceof Long
            || obj instanceof BigInteger || obj instanceof Double || obj instanceof Float)
        builder.append(obj.toString());//from w  ww .  ja v  a  2s  .c o  m
    else if (obj instanceof BigDecimal) {
        String result = obj.toString();
        builder.append(result);
        if (result.indexOf('.') < 0 || result.indexOf('E') < 0 || result.indexOf('e') < 0)
            builder.append(".0");
    } else if (obj instanceof String)
        builder.append("\"")
                // We're using StringEscapeUtils.escapeJava() here, which is the same as escapeJavaScript, except that it doesn't escape ' (which is illegal in JSON strings according to json.org)
                .append(StringEscapeUtils.escapeJava(((String) obj))).append("\"");
    else if (obj instanceof Date) {
        Calendar calendar = new GregorianCalendar();
        calendar.setTime((Date) obj);
        builder.append("new Date(").append(calendar.get(Calendar.YEAR)).append(", ")
                .append(calendar.get(Calendar.MONTH)).append(", ").append(calendar.get(Calendar.DAY_OF_MONTH))
                .append(", ").append(calendar.get(Calendar.HOUR_OF_DAY)).append(", ")
                .append(calendar.get(Calendar.MINUTE)).append(", ").append(calendar.get(Calendar.SECOND));
        int milliSeconds = calendar.get(Calendar.MILLISECOND);
        if (milliSeconds != 0) {
            builder.append(", ").append(milliSeconds);
        }
        builder.append(")");
    } else if (obj instanceof InterpretedTemplate) {
        builder.append("ul4.Template.loads(\"")
                .append(StringEscapeUtils.escapeJavaScript(((InterpretedTemplate) obj).dumps())).append("\")");
    } else if (obj instanceof TemplateClosure) {
        builder.append("ul4.Template.loads(\"")
                .append(StringEscapeUtils.escapeJavaScript(((TemplateClosure) obj).getTemplate().dumps()))
                .append("\")");
    } else if (obj instanceof UL4Attributes) {
        builder.append("{");
        boolean first = true;
        Set<String> attributeNames = ((UL4Attributes) obj).getAttributeNamesUL4();
        for (String attributeName : attributeNames) {
            if (first)
                first = false;
            else
                builder.append(", ");
            call(builder, attributeName);
            builder.append(": ");
            Object value = ((UL4Attributes) obj).getItemStringUL4(attributeName);
            call(builder, value);
        }
        builder.append("}");
    } else if (obj instanceof Color) {
        Color c = (Color) obj;
        builder.append("ul4.Color.create(").append(c.getR()).append(", ").append(c.getG()).append(", ")
                .append(c.getB()).append(", ").append(c.getA()).append(")");
    } else if (obj instanceof Collection) {
        builder.append("[");
        boolean first = true;
        for (Object o : (Collection) obj) {
            if (first)
                first = false;
            else
                builder.append(", ");
            call(builder, o);
        }
        builder.append("]");
    } else if (obj instanceof Object[]) {
        builder.append("[");
        boolean first = true;
        for (Object o : (Object[]) obj) {
            if (first)
                first = false;
            else
                builder.append(", ");
            call(builder, o);
        }
        builder.append("]");
    } else if (obj instanceof Map) {
        builder.append("{");
        boolean first = true;
        Set<Map.Entry> entrySet = ((Map) obj).entrySet();
        for (Map.Entry entry : entrySet) {
            if (first)
                first = false;
            else
                builder.append(", ");
            call(builder, entry.getKey());
            builder.append(": ");
            call(builder, entry.getValue());
        }
        builder.append("}");
    }
}