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.sirma.itt.emf.time.ISO8601DateFormat.java

/**
 * Format calendar instance into ISO format.
 * /*from ww  w .  ja  v a  2 s.c  o m*/
 * @param calendar
 *            the calendar instance to format
 * @return the ISO formatted string
 */
public static String format(Calendar calendar) {
    if (calendar == null) {
        return null;
    }

    StringBuilder formatted = new StringBuilder(28);
    padInt(formatted, calendar.get(Calendar.YEAR), 4);
    formatted.append('-');
    padInt(formatted, calendar.get(Calendar.MONTH) + 1, 2);
    formatted.append('-');
    padInt(formatted, calendar.get(Calendar.DAY_OF_MONTH), 2);
    formatted.append('T');
    padInt(formatted, calendar.get(Calendar.HOUR_OF_DAY), 2);
    formatted.append(':');
    padInt(formatted, calendar.get(Calendar.MINUTE), 2);
    formatted.append(':');
    padInt(formatted, calendar.get(Calendar.SECOND), 2);
    formatted.append('.');
    padInt(formatted, calendar.get(Calendar.MILLISECOND), 3);

    TimeZone tz = calendar.getTimeZone();
    int offset = tz.getOffset(calendar.getTimeInMillis());
    formatted.append(getTimeZonePadding(offset));

    return formatted.toString();
}

From source file:cn.org.awcp.core.utils.DateUtils.java

/**
 * ?<br>/*from w w w. j  a v a 2 s.co m*/
 * ??<br>
 * generate by: vakin jiang at 2012-3-1
 * 
 * @param dateStr
 * @return
 */
public static Date parseDate(String dateStr) {
    SimpleDateFormat format = null;
    if (StringUtils.isBlank(dateStr)) {
        return null;
    }

    String _dateStr = dateStr.trim();
    try {
        if (_dateStr.matches("\\d{1,2}[A-Z]{3}")) {
            _dateStr = _dateStr + (Calendar.getInstance().get(Calendar.YEAR) - 2000);
        }
        // 01OCT12
        if (_dateStr.matches("\\d{1,2}[A-Z]{3}\\d{2}")) {
            format = new SimpleDateFormat("ddMMMyy", Locale.ENGLISH);
        } else if (_dateStr.matches("\\d{1,2}[A-Z]{3}\\d{4}.*")) {// 01OCT2012
            // ,01OCT2012
            // 1224,01OCT2012
            // 12:24
            _dateStr = _dateStr.replaceAll("[^0-9A-Z]", "").concat("000000").substring(0, 15);
            format = new SimpleDateFormat("ddMMMyyyyHHmmss", Locale.ENGLISH);
        } else {
            StringBuffer sb = new StringBuffer(_dateStr);
            String[] tempArr = _dateStr.split("\\s+");
            tempArr = tempArr[0].split("-|\\/");
            if (tempArr.length == 3) {
                if (tempArr[1].length() == 1) {
                    sb.insert(5, "0");
                }
                if (tempArr[2].length() == 1) {
                    sb.insert(8, "0");
                }
            }
            _dateStr = sb.append("000000").toString().replaceAll("[^0-9]", "").substring(0, 14);
            if (_dateStr.matches("\\d{14}")) {
                format = new SimpleDateFormat("yyyyMMddHHmmss");
            }
        }

        Date date = format.parse(_dateStr);
        return date;
    } catch (Exception e) {
        throw new RuntimeException("?[" + dateStr + "]");
    }
}

From source file:com.glaf.core.job.SysDataLogCreateTableJob.java

public void runJob(JobExecutionContext context) throws JobExecutionException {
    String jobName = context.getJobDetail().getKey().getName();
    logger.info("Executing job: " + jobName + " executing at " + DateUtils.getDateTime(new Date()));
    Date date = DateUtils.getDateAfter(new Date(), 0);
    Calendar calendar = Calendar.getInstance();
    calendar.setTime(date);/*from w  w  w.  j  a  v a  2  s  .co  m*/
    int year = calendar.get(Calendar.YEAR);
    int month = calendar.get(Calendar.MONTH);
    int daysOfMonth = DateUtils.getYearMonthDays(year, month + 1);

    calendar.set(year, month, daysOfMonth);

    int begin = getYearMonthDay(date);
    int end = getYearMonthDay(calendar.getTime());

    for (int i = begin; i <= end; i++) {
        try {
            SysDataLogTableUtils.createTable("SYS_DATA_LOG_" + i);
        } catch (Exception ex) {
            ex.printStackTrace();
            logger.error(ex);
        }
    }

}

From source file:net.seratch.taskun.util.CalendarUtil.java

 public static Calendar getCalendar(int yyyy, int mm, int dd) {
   Calendar cal = Calendar.getInstance();
   cal.set(Calendar.YEAR, yyyy);
   cal.set(Calendar.MONTH, mm - 1);
   cal.set(Calendar.DATE, dd);//from  w w w. java 2s  .co  m
   cal.set(Calendar.HOUR_OF_DAY, 0);
   cal.set(Calendar.MINUTE, 0);
   cal.set(Calendar.SECOND, 0);
   cal.set(Calendar.MILLISECOND, 0);
   return cal;
}

From source file:com.cemeterylistingswebtest.test.services.LoginServiceTest.java

@Test
public void AuthenticateTest() {
    loginServ = ctx.getBean(LoginService.class);
    repo = ctx.getBean(SubscriberRepository.class);

    //create subscribers
    userRepo = ctx.getBean(UserRoleRepository.class);

    Calendar calendar = Calendar.getInstance();
    calendar.set(Calendar.YEAR, 2008);
    calendar.set(Calendar.MONTH, Calendar.FEBRUARY);
    calendar.set(Calendar.DATE, 4);

    java.sql.Date javaSqlDate = new java.sql.Date(calendar.getTime().getTime());

    UserRole user = new UserRole.Builder().setLevel(1).build();

    //userRepo.save(user);
    //userRoleID = user.getUserRoleID();

    Subscriber newSub = new Subscriber.Builder().setEmail("manfredOsulivan@horseRaddish.com")
            .setFirstName("Manfred").setSurname("Osulivan").setPwd("jesus").setUsername("ManiFredOssy")
            .setSubscriptionDate(javaSqlDate).setUserRoleID(user).build();

    repo.save(newSub);//from   w  w w . jav a2  s. c  o  m
    id = newSub.getSubscriberID();

    Assert.assertTrue(loginServ.authenticate(newSub.getUsername(), newSub.getPwd()), "Login successful");
    Assert.assertFalse(loginServ.authenticate(newSub.getUsername(), ""), "Login Failed; no password");
    Assert.assertFalse(loginServ.authenticate("", newSub.getPwd()), "Login Failed ; no username");
    Assert.assertFalse(loginServ.authenticate("", ""), "Login Failed no username or password");
}

From source file:com.example.geomesa.transformations.QueryTutorial.java

/**
 * Creates a base filter that will return a small subset of our results. This can be tweaked to
 * return different results if desired. Currently it should return 16 results.
 *
 * @return// w  w w  .  j  a  va  2 s .c om
 *
 * @throws CQLException
 * @throws IOException
 */
static Filter createBaseFilter() throws CQLException, IOException {

    // Get a FilterFactory2 to build up our query
    FilterFactory2 ff = CommonFactoryFinder.getFilterFactory2();

    // We are going to query for events in Ukraine during the
    // civil unrest.

    // We'll start by looking at a particular day in February of 2014
    Calendar calendar = Calendar.getInstance();
    calendar.clear();
    calendar.set(Calendar.YEAR, 2014);
    calendar.set(Calendar.MONTH, Calendar.FEBRUARY);
    calendar.set(Calendar.DAY_OF_MONTH, 2);
    calendar.set(Calendar.HOUR_OF_DAY, 0);
    Date start = calendar.getTime();

    calendar.set(Calendar.HOUR_OF_DAY, 23);
    Date end = calendar.getTime();

    Filter timeFilter = ff.between(ff.property(GdeltFeature.Attributes.SQLDATE.getName()), ff.literal(start),
            ff.literal(end));

    // We'll bound our query spatially to Ukraine
    Filter spatialFilter = ff.bbox(GdeltFeature.Attributes.geom.getName(), 22.1371589, 44.386463, 40.228581,
            52.379581, "EPSG:4326");

    // we'll also restrict our query to only articles about the US, UK or UN
    Filter attributeFilter = ff.like(ff.property(GdeltFeature.Attributes.Actor1Name.getName()), "UNITED%");

    // Now we can combine our filters using a boolean AND operator
    Filter conjunction = ff.and(Arrays.asList(timeFilter, spatialFilter, attributeFilter));

    return conjunction;
}

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;/*from  w w  w .j a v a 2  s. com*/
        add = Integer.parseInt(addField.replaceAll("month", ""));
    } else if (addField.endsWith("year")) {
        field = Calendar.YEAR;
        add = Integer.parseInt(addField.replaceAll("year", ""));
    } else {
        throw new PrefixAndSuffixException("??");
    }
}

From source file:cr.ac.siua.tec.utils.impl.ConstancyPDFGenerator.java

/**
 * Fills the PDF file (constancia.pdf) with the ticket values and returns base64 encoded string.
 *///ww  w  .jav  a  2s.  c o  m
@Override
public String generate(HashMap<String, String> formValues) {
    String originalPdf = PDFGenerator.RESOURCES_PATH + "constancia.pdf";
    try {
        PDDocument _pdfDocument = PDDocument.load(originalPdf);
        PDDocumentCatalog docCatalog = _pdfDocument.getDocumentCatalog();
        PDAcroForm acroForm = docCatalog.getAcroForm();

        //Set some fields manually.
        Calendar cal = Calendar.getInstance();
        int day = cal.get(Calendar.DAY_OF_MONTH);
        int year = cal.get(Calendar.YEAR);
        int month = cal.get(Calendar.MONTH);
        String date = String.valueOf(day) + " de " + monthsMap.get(month) + " del ao " + String.valueOf(year)
                + ".";
        acroForm.getField("Fecha").setValue(date);

        formValues.remove("Queue");
        formValues.remove("Motivo");
        formValues.remove("Requestors");

        //Iterates through remaining custom fields.
        for (Map.Entry<String, String> entry : formValues.entrySet()) {
            acroForm.getField(entry.getKey()).setValue(entry.getValue());
        }
        return encodePDF(_pdfDocument);
    } catch (IOException e) {
        e.printStackTrace();
        System.out.println("Excepcin al llenar el PDF.");
        return null;
    }
}

From source file:net.ceos.project.poi.annotated.bean.SimpleObjectBuilder.java

/**
 * Validate the SimpleObject based on the object build with the method
 * 'buildSimpleObject'/*from  www .ja v a 2 s.c o m*/
 * 
 * @param toValidate
 *            the object to validate
 */
public static void validateSimpleObject(SimpleObject toValidate) {
    SimpleObject base = buildSimpleObject();

    Calendar calendar = Calendar.getInstance();
    calendar.setTime(new Date());

    Calendar calendarUnmarshal = Calendar.getInstance();
    calendarUnmarshal.setTime(toValidate.getDateAttribute());
    assertEquals(calendar.get(Calendar.YEAR), calendarUnmarshal.get(Calendar.YEAR));
    assertEquals(calendar.get(Calendar.MONTH), calendarUnmarshal.get(Calendar.MONTH));
    assertEquals(calendar.get(Calendar.DAY_OF_MONTH), calendarUnmarshal.get(Calendar.DAY_OF_MONTH));
    assertEquals(base.getStringAttribute(), toValidate.getStringAttribute());
    assertEquals(base.getIntegerAttribute(), toValidate.getIntegerAttribute());
    // TODO add new validation below
}

From source file:com.cemeterylistingswebtest.test.domain.SubscriberTest.java

@Test
public void create() {
    System.out.println("Subscriber Test");

    repo = ctx.getBean(SubscriberRepository.class);
    userRepo = ctx.getBean(UserRoleRepository.class);

    Calendar calendar = Calendar.getInstance();
    calendar.set(Calendar.YEAR, 2008);
    calendar.set(Calendar.MONTH, Calendar.FEBRUARY);
    calendar.set(Calendar.DATE, 4);

    java.sql.Date javaSqlDate = new java.sql.Date(calendar.getTime().getTime());

    UserRole user = new UserRole.Builder().setLevel(1).build();

    //userRepo.save(user);
    //userRoleID = user.getUserRoleID();

    Subscriber newSub = new Subscriber.Builder().setEmail("manfredOsulivan@horseRaddish.com")
            .setFirstName("Manfred").setSurname("Osulivan").setPwd("jesus").setUsername("ManiFredOssy")
            .setSubscriptionDate(javaSqlDate).setUserRoleID(user).build();

    repo.save(newSub);//from w  w  w  . j a  v  a2s  .com
    id = newSub.getSubscriberID();
}