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:com.lfv.yada.net.server.ServerLogger.java

public ServerLogger(int groupId, String logpath) {
    // Create a logger for this class
    if (logpath == null) {
        logpath = "data/logs/";
    }//from  ww  w .j  a  va  2s  . c  om
    mylogpath = logpath;
    log = LogFactory.getLog(getClass());
    log.info("ServerLogger: logpath=" + logpath);

    // Create a calendar
    startTime = System.currentTimeMillis();
    calendar = Calendar.getInstance(TimeZone.getTimeZone("UTC"));
    calendar.setTimeInMillis(startTime);
    String filename = "Grp" + groupId + "-" + calendar.get(Calendar.YEAR) + s2(calendar.get(Calendar.MONTH) + 1)
            + s2(calendar.get(Calendar.DAY_OF_MONTH)) + "-" + s2(calendar.get(Calendar.HOUR_OF_DAY))
            + s2(calendar.get(Calendar.MINUTE)) + s2(calendar.get(Calendar.SECOND)) + ".log";
    try {
        printer = new PrintStream(new FileOutputStream(logpath + "/" + filename), true);

        log.info("Creating log " + logpath + "/" + filename);
    } catch (FileNotFoundException ex) {
        log.warn("Log file " + filename + " could not be created, logger has been disabled!", ex);
        printer = null;
    }
}

From source file:es.tekniker.framework.ktek.util.Utils.java

public static long getTimeinMillis4FullDateTimeGMT(int year, int month, int day, int hours, int minutes,
        int seconds) {
    Calendar c = getCalendarGMT();

    c.set(Calendar.YEAR, year);
    c.set(Calendar.MONTH, month);
    c.set(Calendar.DAY_OF_MONTH, day);

    c.set(Calendar.HOUR_OF_DAY, hours);
    c.set(Calendar.MINUTE, minutes);
    c.set(Calendar.SECOND, seconds);

    System.out.println("New Time: " + c.getTime());

    long timeinmillis = c.getTimeInMillis();
    System.out.println(" system time in millis " + timeinmillis);

    return timeinmillis;
}

From source file:com.nagarro.core.validator.PaymentDetailsDTOValidator.java

@Override
public void validate(final Object target, final Errors errors) {
    final PaymentDetailsWsDTO paymentDetails = (PaymentDetailsWsDTO) target;

    if (StringUtils.isNotBlank(paymentDetails.getStartMonth())
            && StringUtils.isNotBlank(paymentDetails.getStartYear())
            && StringUtils.isNotBlank(paymentDetails.getExpiryMonth())
            && StringUtils.isNotBlank(paymentDetails.getExpiryYear())) {
        final Calendar start = Calendar.getInstance();
        start.set(Calendar.DAY_OF_MONTH, 0);
        start.set(Calendar.MONTH, Integer.parseInt(paymentDetails.getStartMonth()) - 1);
        start.set(Calendar.YEAR, Integer.parseInt(paymentDetails.getStartYear()) - 1);

        final Calendar expiration = Calendar.getInstance();
        expiration.set(Calendar.DAY_OF_MONTH, 0);
        expiration.set(Calendar.MONTH, Integer.parseInt(paymentDetails.getExpiryMonth()) - 1);
        expiration.set(Calendar.YEAR, Integer.parseInt(paymentDetails.getExpiryYear()) - 1);

        if (start.after(expiration)) {
            errors.rejectValue("startMonth", "payment.startDate.invalid");
        }//from   ww w .jav  a  2  s.  c o  m
    }

    ValidationUtils.rejectIfEmptyOrWhitespace(errors, "accountHolderName", "field.required");
    ValidationUtils.rejectIfEmptyOrWhitespace(errors, "cardType.code", "field.required");
    ValidationUtils.rejectIfEmptyOrWhitespace(errors, "cardNumber", "field.required");
    ValidationUtils.rejectIfEmptyOrWhitespace(errors, "expiryMonth", "field.required");
    ValidationUtils.rejectIfEmptyOrWhitespace(errors, "expiryYear", "field.required");

    paymentAddressValidator.validate(paymentDetails, errors);
}

From source file:DateUtils.java

/**
 * Get unix style date string./*  w ww .  j  ava 2  s.  c  o m*/
 */
public final static String getUnixDate(long millis) {
    if (millis < 0) {
        return "------------";
    }

    StringBuffer sb = new StringBuffer(16);
    Calendar cal = new GregorianCalendar();
    cal.setTimeInMillis(millis);

    // month
    sb.append(MONTHS[cal.get(Calendar.MONTH)]);
    sb.append(' ');

    // day
    int day = cal.get(Calendar.DATE);
    if (day < 10) {
        sb.append(' ');
    }
    sb.append(day);
    sb.append(' ');

    long sixMonth = 15811200000L; // 183L * 24L * 60L * 60L * 1000L;
    long nowTime = System.currentTimeMillis();
    if (Math.abs(nowTime - millis) > sixMonth) {

        // year
        int year = cal.get(Calendar.YEAR);
        sb.append(' ');
        sb.append(year);
    } else {

        // hour
        int hh = cal.get(Calendar.HOUR_OF_DAY);
        if (hh < 10) {
            sb.append('0');
        }
        sb.append(hh);
        sb.append(':');

        // minute
        int mm = cal.get(Calendar.MINUTE);
        if (mm < 10) {
            sb.append('0');
        }
        sb.append(mm);
    }
    return sb.toString();
}

From source file:cn.com.gps169.server.handler.impl.JT0200Handler.java

@Override
public void handle(Jt808Message msg) {
    JT0200 body = (JT0200) msg.getBody();
    GpsInfo gi = new GpsInfo();
    Date dt = DateUtil.stringToDatetime(body.getTime());
    if (dt == null) {
        Logger.error(String.format(
                "sim?:%s,?%s,??:%s",
                gi.getSimNo(), msg.getSimNo(), body.getTime()));
        return;/*from ww  w  .  j  a  v  a2  s.c o m*/
    }
    Calendar c = Calendar.getInstance();
    c.setTime(dt);
    // ???,?
    if (c.get(Calendar.YEAR) != Calendar.getInstance().get(Calendar.YEAR)) {
        Logger.info(String.format("??:??:%s,?",
                DateUtil.TIMEFORMATER1().format(dt)));
        return;
    }
    if (body.getLatitude() <= 0 || body.getLongitude() <= 0) {
        Logger.info(String.format("?,?? :??:%s",
                DateUtil.TIMEFORMATER1().format(dt)));
        return;
    }
    Terminal tmnl = terminalCacheManager.getTerminalBySimNo(msg.getSimNo());
    TerminalVehicle tv = tmnlVehicleCacheManager.findCurBindRelationsByTerminalId(tmnl.getTerminalId());
    Vehicle vehicle = null;
    if (tv != null) {
        vehicle = vehicleCacheManager.findVehicleById(tv.getVehicleId());
        if (vehicle != null) {
            //?
            gi.setVid(vehicle.getVehicleId());
            if (body.getSpeed() > 1) {
                dataAcquireCacheManager.setRunningStatus(vehicle.getVehicleId(),
                        JT808Constants.VEHICLE_RUNNING_STATUS_RUNNING);
                gi.setRunStatus(JT808Constants.VEHICLE_RUNNING_STATUS_RUNNING);
            } else {
                dataAcquireCacheManager.setRunningStatus(vehicle.getVehicleId(),
                        JT808Constants.VEHICLE_RUNNING_STATUS_STOP);
                gi.setRunStatus(JT808Constants.VEHICLE_RUNNING_STATUS_STOP);
            }
        } else {
            Logger.error("? ?");
            return;
        }
    } else {
        Logger.error("SIM:" + msg.getSimNo());
        return;
    }
    //GPS?
    gi.setTid(tmnl.getTerminalId());
    gi.setSendTime(dt);
    gi.setPlateNo(vehicle.getLicensePlate());
    gi.setSimNo(msg.getSimNo());
    gi.setLatitude(0.000001 * body.getLatitude());
    gi.setLongitude(0.000001 * body.getLongitude());
    gi.setSpeed(0.1 * body.getSpeed());
    gi.setDirection(body.getDirection());
    gi.setStatus(body.getStatus());
    gi.setAlarmStatus(body.getAlarm());
    gi.setMileage(0.1 * body.getMileage());
    gi.setFuel(0.1 * body.getFuel());
    gi.setRecordSpeed(0.1 * body.getRecorderSpeed());
    gi.setAltitude(body.getAltitude());
    gi.setStatus(body.getStatus());
    //???
    gpsHandler.addGps(gi);
    //???
    runningStatusHandler.processData(gi);
    //TODO:?
}

From source file:com.tohours.imo.util.TohoursUtils.java

public static String getCurrentYear() {
    Calendar calendar = Calendar.getInstance();
    return calendar.get(Calendar.YEAR) + "";
}

From source file:com.eryansky.common.utils.DateUtil.java

/**
 *  ?2009-08-01/* w w w .  j  a  v  a 2 s  .c  o m*/
 */
public static String beforeMonth() {
    Calendar localTime = Calendar.getInstance();
    localTime.add(Calendar.MONTH, -1); // ????
    String strz = null;
    int x = localTime.get(Calendar.YEAR); // 
    int y = localTime.get(Calendar.MONTH) + 1; // 
    strz = y >= 10 ? String.valueOf(y) : ("0" + y);
    return x + "-" + strz + "-01";
}

From source file:com.bsb.cms.content.service.utils.PublishUtil.java

public static String getCtURL(String contentId) {
    Calendar date = Calendar.getInstance();
    int month = date.get(Calendar.MONTH) + 1;

    if (StringUtils.isNotBlank(contentId)) {
        return "/" + date.get(Calendar.YEAR) + "/" + (month < 10 ? ("0" + month) : month) + "/" + contentId
                + ".html";
    } else {//from  w  w w. j a v a  2  s.  com
        return "/" + date.get(Calendar.YEAR) + "/" + (month < 10 ? ("0" + month) : month) + "/";
    }

}

From source file:ma.glasnost.orika.test.converter.CloneableConverterTestCase.java

@Test
public void cloneableConverter() throws DatatypeConfigurationException {

    CloneableConverter cc = new CloneableConverter(SampleCloneable.class);

    MapperFactory factory = MappingUtil.getMapperFactory();
    factory.getConverterFactory().registerConverter(cc);

    GregorianCalendar cal = new GregorianCalendar();
    cal.add(Calendar.YEAR, 10);
    XMLGregorianCalendar xmlCal = DatatypeFactory.newInstance()
            .newXMLGregorianCalendar((GregorianCalendar) cal);
    cal.add(Calendar.MONTH, 3);//from   www .j  av a  2  s. com

    ClonableHolder source = new ClonableHolder();
    source.value = new SampleCloneable();
    source.value.id = 5L;
    source.date = new Date(System.currentTimeMillis() + 100000);
    source.timestamp = new Timestamp(System.currentTimeMillis() + 50000);
    source.calendar = cal;
    source.xmlCalendar = xmlCal;

    ClonableHolder dest = factory.getMapperFacade().map(source, ClonableHolder.class);
    Assert.assertEquals(source.value, dest.value);
    Assert.assertNotSame(source.value, dest.value);
    Assert.assertEquals(source.date, dest.date);
    Assert.assertNotSame(source.date, dest.date);
    Assert.assertEquals(source.timestamp, dest.timestamp);
    Assert.assertNotSame(source.timestamp, dest.timestamp);
    Assert.assertEquals(source.calendar, dest.calendar);
    Assert.assertNotSame(source.calendar, dest.calendar);
    Assert.assertEquals(source.xmlCalendar, dest.xmlCalendar);
    Assert.assertNotSame(source.xmlCalendar, dest.xmlCalendar);
}