Example usage for java.util Calendar MONTH

List of usage examples for java.util Calendar MONTH

Introduction

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

Prototype

int MONTH

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

Click Source Link

Document

Field number for get and set indicating the month.

Usage

From source file:com.github.devnied.emvnfccard.utils.TrackUtils.java

/**
 * Extract track 2 data/*from ww  w . ja v  a  2 s  .  co  m*/
 * 
 * @param pEmvCard
 *            Object card representation
 * @param pData
 *            data to parse
 * @return true if the extraction succeed false otherwise
 */
public static boolean extractTrack2Data(final EmvCard pEmvCard, final byte[] pData) {
    boolean ret = false;
    byte[] track2 = TlvUtil.getValue(pData, EmvTags.TRACK_2_EQV_DATA, EmvTags.TRACK2_DATA);

    if (track2 != null) {
        String data = BytesUtils.bytesToStringNoSpace(track2);
        Matcher m = TRACK2_PATTERN.matcher(data);
        // Check pattern
        if (m.find()) {
            // read card number
            pEmvCard.setCardNumber(m.group(1));
            // Read expire date
            SimpleDateFormat sdf = new SimpleDateFormat("yyMM", Locale.getDefault());
            try {
                pEmvCard.setExpireDate(DateUtils.truncate(sdf.parse(m.group(2)), Calendar.MONTH));
            } catch (ParseException e) {
                LOGGER.error("Unparsable expire card date : {}", e.getMessage());
                return ret;
            }
            // Read service
            pEmvCard.setService(new Service(m.group(3)));
            ret = true;
        }
    }
    return ret;
}

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

/**
 * ??n/*from www  . j a  va 2  s  . co  m*/
 * @param n
 * @return
 */
public static String getYearMonth(int n) {
    Calendar calendar = Calendar.getInstance();
    calendar.add(Calendar.MONTH, n);
    String yearMonth = calendar.get(Calendar.YEAR) + "" + formatNum(calendar.get(Calendar.MONTH) + 1)
            + "";
    return yearMonth;
}

From source file:com.pureinfo.srm.project.ProjectToFinishRemindJob.java

private static Date getNMonthLater(int _n) {
    Calendar cal = Calendar.getInstance();
    cal.setTimeZone(TimeZone.getDefault());
    cal.roll(Calendar.MONTH, _n);
    return cal.getTime();
}

From source file:is.idega.idegaweb.egov.gumbo.licenses.SetDraganotveidiValidPeriod.java

private Interval findNearestPeriod(Calendar now) {

    final int year;

    if (now.get(Calendar.MONTH) > Calendar.AUGUST) {

        year = now.get(Calendar.YEAR) + 1;

    } else {//from  w w w  .j  ava2  s  . c  o  m
        year = now.get(Calendar.YEAR);
    }

    final Calendar mayStart = Calendar.getInstance();
    mayStart.set(year, Calendar.MAY, 1, 0, 0, 0);

    final Calendar augEnd = Calendar.getInstance();
    augEnd.set(year, Calendar.AUGUST, 31, 0, 0, 0);

    return new Interval(mayStart.getTime(), augEnd.getTime());
}

From source file:DateUtils.java

public static String getTimestamp() {
    Calendar cal = Calendar.getInstance();
    cal.setTime(new Date());

    int year = cal.get(Calendar.YEAR);
    int month = cal.get(Calendar.MONTH) + 1;
    int day = cal.get(Calendar.DAY_OF_MONTH);
    int hours = cal.get(Calendar.HOUR_OF_DAY);
    // use 24 hour clock
    int minutes = cal.get(Calendar.MINUTE);
    int seconds = cal.get(Calendar.SECOND);
    int milli = cal.get(Calendar.MILLISECOND);

    return "" + year + "-" + month + "-" + day + "_" + formatTime(hours, minutes, seconds, milli);
}

From source file:edu.wisc.my.stats.query.support.UWDataWareHouseInformationProvider.java

public UWDataWareHouseInformationProvider() {
    this.fieldMap.put(Calendar.YEAR, "DD.CALENDAR_YEAR_NUMBER");
    this.fieldMap.put(Calendar.MONTH, "DD.CALENDAR_MONTH_NUMBER");
    this.fieldMap.put(Calendar.DAY_OF_MONTH, "DD.CALENDAR_DAY_NUMBER");
}

From source file:net.netheos.pcsapi.providers.hubic.SwiftTest.java

@Test
public void testParseTimestamp() {
    // Check we won't break if a header is missing :
    Headers headers = new Headers();
    Date timestamp = Swift.parseTimestamp(headers);
    assertNull(timestamp);//from w  ww  .  ja  va 2s.c om

    headers.addHeader("X-Timestamp", "1383925113.43900"); // 2013-11-08T16:38:33.439+01:00
    timestamp = Swift.parseTimestamp(headers);

    Calendar cal = Calendar.getInstance(TimeZone.getTimeZone("GMT"));
    cal.setTime(timestamp);
    System.out.println(timestamp);
    assertEquals(2013, cal.get(Calendar.YEAR));
    assertEquals(Calendar.NOVEMBER, cal.get(Calendar.MONTH));
    assertEquals(8, cal.get(Calendar.DAY_OF_MONTH));
    assertEquals(15, cal.get(Calendar.HOUR_OF_DAY));
    assertEquals(38, cal.get(Calendar.MINUTE));
    assertEquals(33, cal.get(Calendar.SECOND));
    assertEquals(439, cal.get(Calendar.MILLISECOND));

    checkTimestamp("1383925113.430723", new Date(1383925113430L));
    checkTimestamp("1383925113.43900", new Date(1383925113439L));
    checkTimestamp("1383925113.439", new Date(1383925113439L));
    checkTimestamp("1383925113.43", new Date(1383925113430L));
    checkTimestamp("1383925113.4", new Date(1383925113400L));
    checkTimestamp("1383925113.", new Date(1383925113000L));
    checkTimestamp("1383925113", new Date(1383925113000L));
}

From source file:Main.java

public static Date parseDA(TimeZone tz, String s, boolean ceil) {
    Calendar cal = cal(tz);//w ww .  j  a  va 2 s  . co m
    int length = s.length();
    if (!(length == 8 || length == 10 && !Character.isDigit(s.charAt(4))))
        throw new IllegalArgumentException(s);
    try {
        int pos = 0;
        cal.set(Calendar.YEAR, Integer.parseInt(s.substring(pos, pos + 4)));
        pos += 4;
        if (!Character.isDigit(s.charAt(pos)))
            pos++;
        cal.set(Calendar.MONTH, Integer.parseInt(s.substring(pos, pos + 2)) - 1);
        pos += 2;
        if (!Character.isDigit(s.charAt(pos)))
            pos++;
        cal.set(Calendar.DAY_OF_MONTH, Integer.parseInt(s.substring(pos)));
        if (ceil)
            ceil(cal, Calendar.DAY_OF_MONTH);
    } catch (NumberFormatException e) {
        throw new IllegalArgumentException(s);
    }
    return cal.getTime();
}

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.clican.pluto.dataprocess.dpl.function.impl.AddDate.java

public void setParams(List<Object> params) throws DplParseException {
    super.setParams(params);
    this.date = this.pasList.get(0);
    String addField = this.pasList.get(1).getConstantsValue();
    if (addField.endsWith("day")) {
        field = Calendar.DAY_OF_MONTH;
        add = Integer.parseInt(addField.replaceAll("day", ""));
    } else if (addField.endsWith("month")) {
        field = Calendar.MONTH;
        add = Integer.parseInt(addField.replaceAll("month", ""));
    } else if (addField.endsWith("year")) {
        field = Calendar.YEAR;//  w w  w  .  j  a  v a  2 s. c o m
        add = Integer.parseInt(addField.replaceAll("year", ""));
    } else {
        throw new PrefixAndSuffixException("??");
    }
}