Example usage for java.util Date getMonth

List of usage examples for java.util Date getMonth

Introduction

In this page you can find the example usage for java.util Date getMonth.

Prototype

@Deprecated
public int getMonth() 

Source Link

Document

Returns a number representing the month that contains or begins with the instant in time represented by this Date object.

Usage

From source file:org.openmrs.module.pmtct.PregnancyDateManager.java

@SuppressWarnings("deprecation")
public String getDPA(String dateOfPeriod) throws Exception {
    Date lastDateOfPeriod = Context.getDateFormat().parse(dateOfPeriod);

    GregorianCalendar last_DateOfPeriod = new GregorianCalendar(lastDateOfPeriod.getYear() + 1900,
            lastDateOfPeriod.getMonth(), lastDateOfPeriod.getDate());

    last_DateOfPeriod.setLenient(false);
    last_DateOfPeriod.add(Calendar.DAY_OF_YEAR, PMTCTConstants.DELAY_IN_DAYS_OF_PREGNANCY);

    return Context.getDateFormat().format(last_DateOfPeriod.getTime());
}

From source file:nz.co.fortytwo.signalk.util.Util.java

/**
 * Attempt to set the system time using the GPS time
 * //w w w. ja  va 2s  .  c o m
 * @param sen
 */
@SuppressWarnings("deprecation")
public static void checkTime(RMCSentence sen) {
    if (timeSet)
        return;
    try {
        net.sf.marineapi.nmea.util.Date dayNow = sen.getDate();
        // if we need to set the time, we will be WAAYYY out
        // we only try once, so we dont get lots of native processes
        // spawning if we fail
        timeSet = true;
        Date date = new Date();
        if ((date.getYear() + 1900) == dayNow.getYear()) {
            if (logger.isDebugEnabled())
                logger.debug("Current date is " + date);
            return;
        }
        // so we need to set the date and time
        net.sf.marineapi.nmea.util.Time timeNow = sen.getTime();
        String yy = String.valueOf(dayNow.getYear());
        String MM = pad(2, String.valueOf(dayNow.getMonth()));
        String dd = pad(2, String.valueOf(dayNow.getDay()));
        String hh = pad(2, String.valueOf(timeNow.getHour()));
        String mm = pad(2, String.valueOf(timeNow.getMinutes()));
        String ss = pad(2, String.valueOf(timeNow.getSeconds()));
        if (logger.isDebugEnabled())
            logger.debug("Setting current date to " + dayNow + " " + timeNow);
        String cmd = "sudo date --utc " + MM + dd + hh + mm + yy + "." + ss;
        Runtime.getRuntime().exec(cmd.split(" "));// MMddhhmm[[yy]yy]
        if (logger.isDebugEnabled())
            logger.debug("Executed date setting command:" + cmd);
    } catch (Exception e) {
        logger.error(e.getMessage(), e);
    }

}

From source file:org.dspace.statistics.content.StatisticsDataWorkflow.java

private int getMonthsDifference(Date date1, Date date2) {
    int m1 = date1.getYear() * 12 + date1.getMonth();
    int m2 = date2.getYear() * 12 + date2.getMonth();
    return m2 - m1 + 1;
}

From source file:org.alfresco.repo.web.scripts.content.StreamJMXDump.java

/**
 * @see org.springframework.extensions.webscripts.WebScript#execute(org.springframework.extensions.webscripts.WebScriptRequest, org.springframework.extensions.webscripts.WebScriptResponse)
 *///from w  w w.  j a v  a 2 s . c o  m
public void execute(WebScriptRequest req, WebScriptResponse res) throws IOException {
    PrintWriter tempFileOut = null;
    ZipOutputStream zout = null;
    try {
        // content type and caching
        res.setContentType("application/zip");
        Cache cache = new Cache();
        cache.setNeverCache(true);
        cache.setMustRevalidate(true);
        cache.setMaxAge(0L);
        res.setCache(cache);

        Date date = new Date();
        String attachFileName = "jmxdump_" + (date.getYear() + 1900) + '_' + (date.getMonth() + 1) + '_'
                + (date.getDate());
        String headerValue = "attachment; filename=\"" + attachFileName + ".zip\"";

        // set header based on filename - will force a Save As from the browse if it doesn't recognize it
        // this is better than the default response of the browser trying to display the contents
        res.setHeader("Content-Disposition", headerValue);

        // write JMX data to temp file
        File tempFile = TempFileProvider.createTempFile("jmxdump", ".txt");
        tempFileOut = new PrintWriter(tempFile);
        JmxDumpUtil.dumpConnection(mbeanServer, tempFileOut);
        tempFileOut.flush();
        tempFileOut.close();
        tempFileOut = null;

        // zip output
        zout = new ZipOutputStream(res.getOutputStream());
        ZipEntry zipEntry = new ZipEntry(attachFileName + ".txt");
        zout.putNextEntry(zipEntry);
        FileCopyUtils.copy(new FileInputStream(tempFile), zout);
        zout = null;
    } catch (IOException ioe) {
        throw new WebScriptException(Status.STATUS_BAD_REQUEST,
                "Could not output JMX dump: " + ioe.getMessage(), ioe);
    } finally {
        if (tempFileOut != null)
            tempFileOut.close();
        try {
            if (zout != null)
                zout.close();
        } catch (IOException e1) {
        }
    }
}

From source file:org.sonar.plugins.dbcleaner.period.PeriodsTest.java

@Test
public void getDateShouldReturnCurrentTimeMinusDesiredMonths() {
    Project project = new Project("myproject");
    PropertiesConfiguration conf = new PropertiesConfiguration();
    conf.setProperty("KEY", "2");
    project.setConfiguration(conf);/* www.  j a  v  a  2 s  .co  m*/

    Date date = Periods.getDate(conf, "KEY", "2");

    GregorianCalendar calendar = new GregorianCalendar();
    calendar.add(GregorianCalendar.MONTH, -2);
    Date expectedDate = calendar.getTime();

    assertThat(date.getMonth(), is(expectedDate.getMonth()));
}

From source file:com.gizwits.aircondition.activity.control.MainControlActivity.java

/**
 * ??2014624 17:23.//w  w  w. j  a  va 2  s.com
 * 
 * @param date
 *            the date
 * @return the date cn
 */
public static String getDateCN(Date date) {
    int y = date.getYear();
    int m = date.getMonth() + 1;
    int d = date.getDate();

    int h = date.getHours();
    int mt = date.getMinutes();

    return (y + 1900) + "" + m + "" + d + "  " + h + ":" + mt;

}

From source file:com.dare2date.externeservice.lastfm.LastfmAPI.java

/**
 * Adds date data to an event./*  w w  w  . j a v a 2 s . c o m*/
 * @param eventdata
 * @param event
 */
private void addDateToEventFromJSONData(JSONObject eventdata, LastfmEvent event) {
    try {
        Calendar date = Calendar.getInstance();
        Date _date = new SimpleDateFormat("EEE, dd MMM yyyy HH:mm:ss", Locale.ENGLISH)
                .parse(eventdata.get("startDate").toString());
        date.set(_date.getYear(), _date.getMonth(), _date.getDay(), _date.getHours(), _date.getMinutes(),
                _date.getSeconds());
        event.setStartDate(date);
    } catch (ParseException e) {
        e.printStackTrace();
    }
}

From source file:TimeFormatter.java

/**
 * Format the given date as a string, according to the given
 * format string./*from   ww  w . j  a  v a  2s. co  m*/
 * The format string is of the form used by the strftime(3) UNIX
 * call.
 * @param date The date to format
 * @param format The formatting string
 * @return the String with the formatted date.  */
public static String format(Date date, String format) {
    StringBuffer buf = new StringBuffer(50);
    char ch;
    for (int i = 0; i < format.length(); i++) {
        ch = format.charAt(i);
        if (ch == '%') {
            ++i;
            if (i == format.length())
                break;
            ch = format.charAt(i);
            if (ch == 'E') {
                // Alternate Era
                ++i;
            } else if (ch == 'Q') {
                // Alternate numeric symbols
                ++i;
            }
            if (i == format.length())
                break;
            ch = format.charAt(i);
            switch (ch) {
            case 'A':
                buf.append(fullWeekDays[date.getDay()]);
                break;
            case 'a':
                buf.append(abrWeekDays[date.getDay()]);
                break;

            case 'B':
                buf.append(fullMonths[date.getMonth()]);
                break;

            case 'b':
            case 'h':
                buf.append(abrMonths[date.getMonth()]);
                break;

            case 'C':
                appendPadded(buf, (date.getYear() + 1900) / 100, 2);
                break;

            case 'c':
                buf.append(date.toLocaleString());
                break;

            case 'D':
                buf.append(TimeFormatter.format(date, "%m/%d/%y"));
                break;

            case 'd':
                appendPadded(buf, date.getDate(), 2);
                break;

            case 'e':
                appendPadded(buf, date.getMonth() + 1, 2, ' ');
                break;

            case 'H':
                appendPadded(buf, date.getHours(), 2);
                break;

            case 'I':
            case 'l':
                int a = date.getHours() % 12;
                if (a == 0)
                    a = 12;
                appendPadded(buf, a, 2, ch == 'I' ? '0' : ' ');
                break;

            case 'j':
                buf.append("[?]");
                // No simple way to get this as of now
                break;

            case 'k':
                appendPadded(buf, date.getHours(), 2, ' ');
                break;

            case 'M':
                appendPadded(buf, date.getMinutes(), 2);
                break;

            case 'm':
                appendPadded(buf, date.getMonth() + 1, 2);
                break;

            case 'n':
                buf.append('\n');
                break;

            case 'p':
                buf.append(date.getHours() < 12 ? "am" : "pm");
                break;

            case 'R':
                buf.append(TimeFormatter.format(date, "%H:%M"));
                break;

            case 'r':
                buf.append(TimeFormatter.format(date, "%l:%M%p"));
                break;

            case 'S':
                appendPadded(buf, date.getSeconds(), 2);
                break;

            case 'T':
                buf.append(TimeFormatter.format(date, "%H:%M:%S"));
                break;

            case 't':
                buf.append('\t');
                break;

            case 'U':
            case 'u':
            case 'V':
            case 'W':
                buf.append("[?]");
                // Weekdays are a pain, especially
                // without day of year (0-365) ;
                break;

            case 'w':
                buf.append(date.getDay());
                break;

            case 'X':
                buf.append(TimeFormatter.format(date, "%H:%M:%S"));
                break;

            case 'x':
                buf.append(TimeFormatter.format(date, "%B %e, %Y"));
                break;

            case 'y':
                appendPadded(buf, (date.getYear() + 1900) % 100, 2);
                break;

            case 'Y':
                appendPadded(buf, (date.getYear() + 1900), 4);
                break;

            case 'Z':
                String strdate = date.toString();
                buf.append(strdate.substring(20, 23));
                // (!)
                // There should be a better way
                // to do this...
                break;
            case '%':
                buf.append('%');
                break;

            }
        } else {
            buf.append(ch);
        }
    }
    return buf.toString();
}

From source file:us.fatehi.creditcardnumber.ExpirationDate.java

/**
 * Expiration date from year and month./*from w  w w.  j  a v a 2 s.c o  m*/
 *
 * @param year
 *        Year
 * @param month
 *        Month
 */
public ExpirationDate(final Date date) {
    super(null);
    if (date != null) {
        expirationDate = YearMonth.of(date.getYear() + 1900, date.getMonth() + 1);
    } else {
        expirationDate = null;
    }
}

From source file:graficos.GraficoGantt.java

private Date getFechaIncremento(Date fecha_com, int unidad_tiempo, int incremento) {
    Calendar calendario = Calendar.getInstance();
    calendario.set(fecha_com.getYear() + 1900, fecha_com.getMonth(), fecha_com.getDate());
    if (unidad_tiempo == Calendar.DATE)
        calendario.add(Calendar.DATE, incremento);
    else if (unidad_tiempo == Calendar.MONTH)
        calendario.add(Calendar.MONTH, incremento);
    else/*w  w w  . j  a v  a 2s  .  c  o  m*/
        calendario.add(Calendar.YEAR, incremento);
    Date fecha = calendario.getTime();
    return fecha;
}