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.google.orkut.client.api.Util.java

static String getFormattedTimestamp(long timeMillis) {
    Calendar cal = Calendar.getInstance(TimeZone.getTimeZone(Constants.DateFormatter.UTC));
    cal.setTimeInMillis(timeMillis);//from w  w w  .j  a v  a2s.c o  m
    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.liusoft.dlog4j.util.DateUtils.java

/**
 * ??/*from   w w  w. j a va 2  s .c o m*/
 * @param year
 * @param month
 * @param date
 * @return
 */
public static Calendar getDateBegin(int year, int month, int date) {
    Calendar begin_time = Calendar.getInstance();
    begin_time.set(Calendar.YEAR, year);
    begin_time.set(Calendar.MONTH, month - 1);
    begin_time.set(Calendar.DATE, date);
    begin_time.set(Calendar.HOUR_OF_DAY, 0);
    begin_time.set(Calendar.MINUTE, 0);
    begin_time.set(Calendar.SECOND, 0);
    begin_time.set(Calendar.MILLISECOND, 0);
    return begin_time;
}

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

 public static Calendar getCalendar(String yyyy, String mm, String dd) {
   Calendar cal = Calendar.getInstance();
   cal.set(Calendar.YEAR, Integer.valueOf(yyyy));
   cal.set(Calendar.MONTH, Integer.valueOf(mm) - 1);
   cal.set(Calendar.DATE, Integer.valueOf(dd));
   cal.set(Calendar.HOUR_OF_DAY, 0);
   cal.set(Calendar.MINUTE, 0);/*w w w  .  ja v a  2s. c  o  m*/
   cal.set(Calendar.SECOND, 0);
   cal.set(Calendar.MILLISECOND, 0);
   return cal;
}

From source file:dumbara.view.Chart1.java

public static void byIncome() {
    DefaultCategoryDataset objDataset = new DefaultCategoryDataset();
    try {/*  ww w.j a v a  2  s.co m*/
        Sale[] sale = SalesController.viewAllSales();
        for (Sale sale1 : sale) {
            objDataset.setValue(sale1.getIncome(), "Sales Progress", sale1.getSalesID());
        }
    } catch (ClassNotFoundException | SQLException ex) {
        Logger.getLogger(Chart1.class.getName()).log(Level.SEVERE, null, ex);
    }
    Calendar cal = Calendar.getInstance();
    cal.add(Calendar.MONTH, -1);
    Date result = cal.getTime();
    SimpleDateFormat simpleDateFormat = new SimpleDateFormat("E yyyy.MM.dd");
    String format = simpleDateFormat.format(result);
    Date date = new Date();
    String format1 = simpleDateFormat.format(date);

    JFreeChart objChart = ChartFactory.createBarChart(
            "Sales Comparisson by Sales ID from " + format + " to " + format1, "Sales ID", "Sales Income",
            objDataset, PlotOrientation.VERTICAL, true, true, false

    );
    ChartFrame frame = new ChartFrame("Data Analysis Wizard - v2.1.4", objChart);
    frame.pack();
    frame.setSize(1300, 600);
    frame.setVisible(true);
    frame.setLocationRelativeTo(null);
}

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

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

        //Set some fields manually.
        Calendar cal = Calendar.getInstance();
        int year = cal.get(Calendar.YEAR);
        int month = cal.get(Calendar.MONTH) + 1;
        if (month > 10 || month < 5)
            acroForm.getField("Semestre").setValue("PRIMER");
        else
            acroForm.getField("Semestre").setValue("SEGUNDO");

        if (month > 10 && acroForm.getField("Semestre").getValue().equals("PRIMER"))
            year++;

        acroForm.getField("Ao").setValue(String.valueOf(year));
        formValues.remove("Queue");
        acroForm.getField(formValues.get("Banco")).setValue("x");
        formValues.remove("Banco");
        acroForm.getField(formValues.get("Tipo de asistencia")).setValue("x");
        formValues.remove("Tipo de asistencia");

        //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.sf.sze.service.impl.common.SchulKalenderServiceImpl.java

/**
 * {@inheritDoc}/*from  w  w w  . jav  a  2 s. co m*/
 */
@Override
public Halbjahr getHalbjahr(final Calendar currentDate) {
    if (currentDate.get(Calendar.MONTH) >= Calendar.MARCH
            && currentDate.get(Calendar.MONTH) < Calendar.AUGUST) {
        return Halbjahr.Beide_Halbjahre;
    } else {
        return Halbjahr.Erstes_Halbjahr;
    }
}

From source file:WebCalendar.java

/** */
public void setMonth(int _iMonth) {
    m_gc.set(Calendar.MONTH, _iMonth);
}

From source file:helper.lang.DateHelperTest.java

@Test
public void testAsUtcDayCalendar() {
    Calendar localTime = Calendar.getInstance(TimeZone.getTimeZone("CST"));
    Calendar cal = DateHelper.asUtcDay(localTime);
    assertEquals(0, cal.get(Calendar.MILLISECOND));
    assertEquals(0, cal.get(Calendar.MINUTE));
    assertEquals(0, cal.get(Calendar.HOUR));
    assertEquals(0, cal.get(Calendar.HOUR_OF_DAY));
    assertEquals(DateHelper.UTC_TIME_ZONE, cal.getTimeZone());
    assertEquals(TimeZone.getTimeZone("CST"), localTime.getTimeZone());
    assertEquals(localTime.get(Calendar.YEAR), cal.get(Calendar.YEAR));
    assertEquals(localTime.get(Calendar.MONTH), cal.get(Calendar.MONTH));
    assertEquals(localTime.get(Calendar.DATE), cal.get(Calendar.DATE));
}

From source file:DateUtils.java

/**
 * Get unix style date string./*from   ww  w .  j av  a2  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:Main.java

public static Date getDateTimeFrom(Date time, Date date) {
    Date iTime, iDate;/*from w  w w. j  a v a  2 s.c om*/
    Calendar calendar = Calendar.getInstance();

    if (date == null) {
        iTime = time;
        iDate = new Date();
    } else {
        iTime = time;
        iDate = date;
    }

    Calendar calendarDate = Calendar.getInstance();
    calendarDate.setTime(iDate);

    Calendar calendarTime = Calendar.getInstance();
    if (iTime != null)
        calendarTime.setTime(iTime);

    if (iTime != null) {
        calendar.set(Calendar.MINUTE, calendarTime.get(Calendar.MINUTE));
        calendar.set(Calendar.HOUR_OF_DAY, calendarTime.get(Calendar.HOUR_OF_DAY));
    } else {
        calendar.set(Calendar.MINUTE, 0);
        calendar.set(Calendar.HOUR_OF_DAY, 0);
        calendar.set(Calendar.SECOND, 0);
        calendar.set(Calendar.MILLISECOND, 0);
    }

    //calendar.set(Calendar.AM_PM, calendarTime.get(Calendar.AM_PM) );

    calendar.set(Calendar.DAY_OF_MONTH, calendarDate.get(Calendar.DAY_OF_MONTH));
    calendar.set(Calendar.MONTH, calendarDate.get(Calendar.MONTH));
    calendar.set(Calendar.YEAR, calendarDate.get(Calendar.YEAR));

    Date ret = calendar.getTime();
    Log.v("!!!!!!!!!! calendar=", "" + ret);

    return ret;
}