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

public Object calculate(Map<String, Object> row) throws CalculationException, PrefixAndSuffixException {
    Date d = date.getValue(row);//w w w.j ava2 s .  co  m
    d = DateUtils.truncate(d, Calendar.MONTH);
    d = DateUtils.addMonths(d, 1);
    d = DateUtils.addDays(d, -1);
    SimpleDateFormat sdf = new SimpleDateFormat("dd");
    return Integer.parseInt(sdf.format(d));
}

From source file:Main.java

/**
 * Given a calendar (possibly containing only a day of the year), returns the earliest possible
 * anniversary of the date that is equal to or after the current point in time if the date
 * does not contain a year, or the date converted to the local time zone (if the date contains
 * a year./*from w ww  . j  a va 2 s  . co m*/
 *
 * @param target The date we wish to convert(in the UTC time zone).
 * @return If date does not contain a year (year < 1900), returns the next earliest anniversary
 * that is after the current point in time (in the local time zone). Otherwise, returns the
 * adjusted Date in the local time zone.
 */
public static Date getNextAnnualDate(Calendar target) {
    final Calendar today = Calendar.getInstance();
    today.setTime(new Date());

    // Round the current time to the exact start of today so that when we compare
    // today against the target date, both dates are set to exactly 0000H.
    today.set(Calendar.HOUR_OF_DAY, 0);
    today.set(Calendar.MINUTE, 0);
    today.set(Calendar.SECOND, 0);
    today.set(Calendar.MILLISECOND, 0);

    final boolean isYearSet = isYearSet(target);
    final int targetYear = target.get(Calendar.YEAR);
    final int targetMonth = target.get(Calendar.MONTH);
    final int targetDay = target.get(Calendar.DAY_OF_MONTH);
    final boolean isFeb29 = (targetMonth == Calendar.FEBRUARY && targetDay == 29);
    final GregorianCalendar anniversary = new GregorianCalendar();
    // Convert from the UTC date to the local date. Set the year to today's year if the
    // there is no provided year (targetYear < 1900)
    anniversary.set(!isYearSet ? today.get(Calendar.YEAR) : targetYear, targetMonth, targetDay);
    // If the anniversary's date is before the start of today and there is no year set,
    // increment the year by 1 so that the returned date is always equal to or greater than
    // today. If the day is a leap year, keep going until we get the next leap year anniversary
    // Otherwise if there is already a year set, simply return the exact date.
    if (!isYearSet) {
        int anniversaryYear = today.get(Calendar.YEAR);
        if (anniversary.before(today) || (isFeb29 && !anniversary.isLeapYear(anniversaryYear))) {
            // If the target date is not Feb 29, then set the anniversary to the next year.
            // Otherwise, keep going until we find the next leap year (this is not guaranteed
            // to be in 4 years time).
            do {
                anniversaryYear += 1;
            } while (isFeb29 && !anniversary.isLeapYear(anniversaryYear));
            anniversary.set(anniversaryYear, targetMonth, targetDay);
        }
    }
    return anniversary.getTime();
}

From source file:CalendarDemo.java

public void format() {

    // Tell the calendar what date/time to format
    calendar.setTime(timeNow);/*from w  w w . j av  a 2s.com*/

    // print out most of the known fields
    System.out.println("ERA: " + calendar.get(Calendar.ERA));
    System.out.println("YEAR: " + calendar.get(Calendar.YEAR));
    System.out.println("MONTH: " + calendar.get(Calendar.MONTH));
    System.out.println("WEEK_OF_YEAR: " + calendar.get(Calendar.WEEK_OF_YEAR));
    System.out.println("WEEK_OF_MONTH: " + calendar.get(Calendar.WEEK_OF_MONTH));
    System.out.println("DATE: " + calendar.get(Calendar.DATE));
    System.out.println("DAY_OF_MONTH: " + calendar.get(Calendar.DAY_OF_MONTH));
    System.out.println("DAY_OF_YEAR: " + calendar.get(Calendar.DAY_OF_YEAR));
    System.out.println("DAY_OF_WEEK: " + calendar.get(Calendar.DAY_OF_WEEK));
    System.out.println("DAY_OF_WEEK_IN_MONTH: " + calendar.get(Calendar.DAY_OF_WEEK_IN_MONTH));
    System.out.println("AM_PM: " + calendar.get(Calendar.AM_PM));
    System.out.println("HOUR: " + calendar.get(Calendar.HOUR));
    System.out.println("HOUR_OF_DAY: " + calendar.get(Calendar.HOUR_OF_DAY));
    System.out.println("MINUTE: " + calendar.get(Calendar.MINUTE));
    System.out.println("SECOND: " + calendar.get(Calendar.SECOND));
    System.out.println("MILLISECOND: " + calendar.get(Calendar.MILLISECOND));
    System.out.println("ZONE_OFFSET: " + (calendar.get(Calendar.ZONE_OFFSET) / (60 * 60 * 1000)));
    System.out.println("DST_OFFSET: " + (calendar.get(Calendar.DST_OFFSET) / (60 * 60 * 1000)));
}

From source file:sg.edu.ntu.hrms.service.EmployeeListService.java

public String getInitialPrevMonths(int months) {
    SimpleDateFormat formatter = new SimpleDateFormat("MM/dd/yyyy");
    Date current = new Date();
    Calendar frmCal = Calendar.getInstance();
    frmCal.add(Calendar.MONTH, -1 * months);
    String frmDate = formatter.format(frmCal.getTime());
    String toDate = formatter.format(current);
    StringBuilder sb = new StringBuilder();
    sb.append(frmDate).append(" - ").append(toDate);

    return sb.toString();
}

From source file:ezbake.services.provenance.graph.Utils.java

public static ezbake.base.thrift.DateTime convertDate2DateTime(final java.util.Date theDate) {
    final Calendar cal = new GregorianCalendar();
    cal.setTime(theDate);//  w  w  w . j  a  va  2 s.  co m

    // get calendar parts
    final int year = cal.get(Calendar.YEAR);
    final int month = cal.get(Calendar.MONTH) + 1;
    final int day = cal.get(Calendar.DAY_OF_MONTH);
    final int hour = cal.get(Calendar.HOUR_OF_DAY);
    final int minute = cal.get(Calendar.MINUTE);
    final int second = cal.get(Calendar.SECOND);
    int offsetMinutes = (cal.getTimeZone().getOffset(cal.getTimeInMillis())) / (1000 * 60);

    // set thrift DateTime propertiesd
    final ezbake.base.thrift.DateTime dt = new ezbake.base.thrift.DateTime();
    // Date
    final ezbake.base.thrift.Date date = new ezbake.base.thrift.Date();
    date.setMonth((short) month).setDay((short) day).setYear((short) year);
    dt.setDate(date);

    // Time with TimeZone
    final ezbake.base.thrift.Time t = new ezbake.base.thrift.Time();
    boolean afterUtc = offsetMinutes > 0;
    offsetMinutes = Math.abs(offsetMinutes);
    final ezbake.base.thrift.TimeZone tz = new ezbake.base.thrift.TimeZone((short) (offsetMinutes / 60),
            (short) (offsetMinutes % 60), afterUtc);
    t.setHour((short) hour).setMinute((short) minute).setSecond((short) second).setTz(tz);
    dt.setTime(t);

    return dt;
}

From source file:com.metamug.mtg.s3.uploader.S3Uploader.java

public static String upload(InputStream inputStream, long fileSize, String URI) {
    String publicURL;//www. j a va  2s. c  om
    //ClientConfiguration max retry
    ObjectMetadata objectMetaData = new ObjectMetadata();
    objectMetaData.setContentLength(fileSize);
    //        objectMetaData.setContentType(IMAGE_CONTENT_TYPE);
    objectMetaData.setCacheControl("public");
    Calendar c = Calendar.getInstance();
    c.setTime(c.getTime());
    c.add(Calendar.MONTH, 6);
    String sdf = new SimpleDateFormat("EEE, d MMM yyyy HH:mm:ss zzz").format(c.getTime());
    objectMetaData.setHeader("Expires", sdf);//Thu, 21 Mar 2042 08:16:32 GMT

    PutObjectResult por = s3Client
            .putObject(new PutObjectRequest(AWS_S3_BUCKET, URI, inputStream, objectMetaData)
                    .withCannedAcl(CannedAccessControlList.PublicRead));

    publicURL = "http://metamug.net/" + URI;
    return publicURL;
}

From source file:Main.java

/**
 * Get current month/*www.j  a va 2 s  .  c  om*/
 *
 * @return
 */
public static int getCurrentMonth() {
    return Calendar.getInstance().get(Calendar.MONTH) + 1;
}

From source file:com.ar.dev.tierra.api.service.FacturaService.java

public Page getFacturasMonth(Integer page, Integer size, int idSucursal) {
    Calendar calendar = Calendar.getInstance();
    Date toDate = calendar.getTime();
    calendar.add(Calendar.MONTH, -1);
    Date fromDate = calendar.getTime();
    Page facturas = facturaRepository.findFacturasByDate(fromDate, toDate, new PageRequest(page, size),
            idSucursal);//www .  j av a2  s.com
    return facturas;
}

From source file:edu.stanford.muse.email.CalendarUtil.java

public static String getDisplayMonth(Calendar c) {
    // we don't want to be dependent on Calendar.getDisplayName() which is in java 1.6 only
    // return c.getDisplayName(Calendar.MONTH, Calendar.LONG, Locale.getDefault()) + " " + c.get(Calendar.YEAR);
    // could also use a simpledataformat here.
    int month = c.get(Calendar.MONTH); // month is 0-based
    return monthStrings[month];
}

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

private static Calendar getTimeToday(Calendar _today, String _sTime) {
    Calendar todayTime = new GregorianCalendar();
    try {//from w  w w . j a v a2 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;
}