Example usage for java.util Calendar MINUTE

List of usage examples for java.util Calendar MINUTE

Introduction

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

Prototype

int MINUTE

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

Click Source Link

Document

Field number for get and set indicating the minute within the hour.

Usage

From source file:Main.java

/**
 * Add date time with nine minutes./*  w  w w .j a  va2  s  . c  o  m*/
 *
 * @param listing     the listing
 * @param currentTime the current time
 * @param isPast      true/false if past time
 */
private static void addDateTimeWithNineMinutes(final List<Long> listing, final long currentTime,
        final boolean isPast) {
    final Calendar calendar = Calendar.getInstance();
    calendar.setTimeInMillis(currentTime);
    calendar.add(Calendar.MINUTE, isPast ? -9 : 9);
    listing.add(calendar.getTimeInMillis());
}

From source file:DateUtil.java

/**
 * Returns a Date set to the first possible millisecond of the day, just
 * after midnight. If a null day is passed in, a new Date is created.
 * midnight (00m 00h 00s)//from w ww. j  ava2  s.c  om
 */
public static Date getStartOfDay(Date day, Calendar cal) {
    if (day == null)
        day = new Date();
    cal.setTime(day);
    cal.set(Calendar.HOUR_OF_DAY, cal.getMinimum(Calendar.HOUR_OF_DAY));
    cal.set(Calendar.MINUTE, cal.getMinimum(Calendar.MINUTE));
    cal.set(Calendar.SECOND, cal.getMinimum(Calendar.SECOND));
    cal.set(Calendar.MILLISECOND, cal.getMinimum(Calendar.MILLISECOND));
    return cal.getTime();
}

From source file:ru.org.linux.search.SearchControlController.java

@RequestMapping(value = "/admin/search-reindex", method = RequestMethod.POST, params = "action=all")
@PreAuthorize("hasRole('ROLE_ADMIN')")
public ModelAndView reindexAll(ServletRequest request) throws Exception {

    Timestamp startDate = messageDao.getTimeFirstTopic();

    Calendar start = Calendar.getInstance();
    start.setTime(startDate);/*from   ww w  .j a  v  a  2  s .c om*/

    start.set(Calendar.DAY_OF_MONTH, 1);
    start.set(Calendar.HOUR, 0);
    start.set(Calendar.MINUTE, 0);

    for (Calendar i = Calendar.getInstance(); i.after(start); i.add(Calendar.MONTH, -1)) {
        searchQueueSender.updateMonth(i.get(Calendar.YEAR), i.get(Calendar.MONTH) + 1);
    }

    searchQueueSender.updateMonth(1970, 1);

    return new ModelAndView("action-done", "message", "Scheduled reindex");
}

From source file:adalid.commons.util.TimeUtils.java

public static synchronized Date currentDate() {
    calendar.setTimeInMillis(currentTimeMillis());
    calendar.set(Calendar.HOUR_OF_DAY, 0);
    calendar.set(Calendar.MINUTE, 0);
    calendar.set(Calendar.SECOND, 0);
    calendar.set(Calendar.MILLISECOND, 0);
    return new Date(calendar.getTimeInMillis());
}

From source file:com.spoiledmilk.cykelsuperstier.break_rote.STrainData.java

public static ArrayList<ITransportationInfo> getNext3Arrivals(String stationFrom, String stationTo, String line,
        Context context) {//from w ww . j  av  a 2  s  .  co  m
    ArrayList<ITransportationInfo> ret = new ArrayList<ITransportationInfo>();
    try {
        String bufferString = Util.stringFromJsonAssets(context, "stations/" + filename);
        JsonNode actualObj = Util.stringToJsonNode(bufferString);
        JsonNode lines = actualObj.get("timetable");

        // find the data for the current transportation line
        for (int i = 0; i < lines.size(); i++) {
            JsonNode lineJson = lines.get(i);
            String[] sublines = line.split(",");
            for (int ii = 0; ii < sublines.length; ii++) {
                if (lineJson.get("line").asText().equalsIgnoreCase(sublines[ii].trim())) {
                    int day = Calendar.getInstance().get(Calendar.DAY_OF_WEEK);
                    if (day == 1)
                        day = 6;
                    else
                        day -= 2;
                    int hour = Calendar.getInstance().get(Calendar.HOUR_OF_DAY);
                    int minute = Calendar.getInstance().get(Calendar.MINUTE);
                    JsonNode stationData = null;
                    if ((day == 4 || day == 5)
                            && isFridaySaturdayNight(lineJson.get("night-after-friday-saturday"), hour)) {
                        // night after Friday or Saturday
                        stationData = lineJson.get("night-after-friday-saturday");
                    } else if (day < 5) {
                        // weekdays
                        stationData = lineJson.get("weekdays");
                    } else {
                        // weekend
                        stationData = lineJson.get("weekend");
                    }
                    JsonNode stations = stationData.get("data");
                    int[] AStationMinutes = null, BStationMinutes = null;
                    // find the data for the start and end station and choose the direction
                    direction = NOT_SET;
                    for (int j = 0; j < stations.size(); j++) {
                        JsonNode st = stations.get(j);
                        if (st.get("station").asText().equalsIgnoreCase(stationFrom) && direction == NOT_SET
                                && AStationMinutes == null) {
                            direction = DEPARTURE;
                            AStationMinutes = getMinutesArray(st.get("departure").asText());
                        } else if (st.get("station").asText().equalsIgnoreCase(stationFrom)
                                && AStationMinutes == null) {
                            AStationMinutes = getMinutesArray(st.get("arrival").asText());
                            break;
                        } else if (st.get("station").asText().equalsIgnoreCase(stationTo)
                                && direction == NOT_SET && BStationMinutes == null) {
                            direction = ARRIVAL;
                            BStationMinutes = getMinutesArray(st.get("departure").asText());
                        } else if (st.get("station").asText().equalsIgnoreCase(stationTo)
                                && BStationMinutes == null) {
                            BStationMinutes = getMinutesArray(st.get("arrival").asText());
                            break;
                        }
                    }
                    if (AStationMinutes == null || BStationMinutes == null)
                        continue;
                    JsonNode subLines = direction == DEPARTURE ? stationData.get("departure")
                            : stationData.get("arrival");
                    JsonNode subLine = subLines.get(0);
                    if (hasTrain(hour, subLine.get("night").asText(), subLine.get("day").asText())) {
                        int count = 0;
                        for (int k = 0; k < AStationMinutes.length; k++) {
                            if (minute <= AStationMinutes[k]) {
                                int arrivalHour = hour;
                                int time = BStationMinutes[k] - AStationMinutes[k];
                                if (AStationMinutes[k] > BStationMinutes[k]) {
                                    arrivalHour++;
                                    time = 60 - AStationMinutes[k] + BStationMinutes[k];
                                }
                                ret.add(new STrainData(
                                        (hour < 10 ? "0" + hour : "" + hour) + ":"
                                                + (AStationMinutes[k] < 10 ? "0" + AStationMinutes[k]
                                                        : "" + AStationMinutes[k]),
                                        (arrivalHour < 10 ? "0" + arrivalHour : "" + arrivalHour) + ":"
                                                + (BStationMinutes[k] < 10 ? "0" + BStationMinutes[k]
                                                        : "" + BStationMinutes[k]),
                                        time));
                                if (++count == 3)
                                    break;
                            }
                        }
                        // second pass to get the times for the next hour
                        hour++;
                        for (int k = 0; k < AStationMinutes.length && count < 3; k++) {
                            int arrivalHour = hour;
                            int time = BStationMinutes[k] - AStationMinutes[k];
                            if (AStationMinutes[k] > BStationMinutes[k]) {
                                arrivalHour++;
                                time = 60 - AStationMinutes[k] + BStationMinutes[k];
                            }
                            ret.add(new STrainData(
                                    (hour < 10 ? "0" + hour : "" + hour) + ":"
                                            + (AStationMinutes[k] < 10 ? "0" + AStationMinutes[k]
                                                    : "" + AStationMinutes[k]),
                                    (arrivalHour < 10 ? "0" + arrivalHour : "" + arrivalHour) + ":"
                                            + (BStationMinutes[k] < 10 ? "0" + BStationMinutes[k]
                                                    : "" + BStationMinutes[k]),
                                    time));
                        }
                    }
                    return ret;
                }
            }
        }
    } catch (Exception e) {
        if (e != null && e.getLocalizedMessage() != null)
            LOG.e(e.getLocalizedMessage());
    }

    return ret;
}

From source file:org.psidnell.omnifocus.expr.ExpressionFunctionsTest.java

@Test
public void testDateRoundToDay() throws ParseException {
    Date date1 = ExpressionFunctions.roundToDay(new Date());

    Calendar cal2 = new GregorianCalendar();

    assertNotEquals(date1, cal2.getTime());

    cal2.set(Calendar.HOUR_OF_DAY, 0);
    cal2.set(Calendar.MINUTE, 0);
    cal2.set(Calendar.SECOND, 0);
    cal2.set(Calendar.MILLISECOND, 0);

    assertEquals(date1, cal2.getTime());
}

From source file:net.kamhon.ieagle.util.DateUtil.java

public static Date formatDateByTime(Date date, int hour, int minute, int second, int milisecond) {
    Calendar calendar = setTime(date);
    calendar.set(Calendar.HOUR_OF_DAY, hour);
    calendar.set(Calendar.MINUTE, minute);
    calendar.set(Calendar.SECOND, second);
    calendar.set(Calendar.MILLISECOND, milisecond);

    return calendar.getTime();
}

From source file:Controller.Movimientos.generatePDF.java

public void generateAgendaEmpleados() {
    mm = new Model_Movimientos();
    try {//from   w w  w. j a v a2 s.  com

        Calendar calendar = Calendar.getInstance();
        int dayOfMonth = calendar.get(Calendar.DAY_OF_MONTH);
        int monthOfYear = calendar.get(Calendar.MONTH);
        int year = calendar.get(Calendar.YEAR);
        int hour = calendar.get(Calendar.HOUR_OF_DAY);
        int min = calendar.get(Calendar.MINUTE);
        int sec = calendar.get(Calendar.SECOND);

        Document documento = new Document();//Creamos el documento
        FileOutputStream ficheroPdf = new FileOutputStream("agendaEmpleados" + dayOfMonth + "--" + monthOfYear
                + "--" + year + " " + hour + ";" + min + ";" + sec + ".pdf");//Abrimos el flujo y le asignamos nombre al pdf y su direccion
        PdfWriter.getInstance(documento, ficheroPdf).setInitialLeading(20);//Instanciamos el documento con el fichero

        documento.open();//Abrimos el documento

        documento.add(new Paragraph("Lista Empleados",
                FontFactory.getFont("Calibri", 30, Font.BOLD, BaseColor.BLACK)));//Le indicamos el tipo de letra, el tamanio, el estilo y el color de la letra
        documento.add(new Paragraph("___________________________"));//Realiza un salto de linea
        Iterator it;
        it = mm.getCrews().iterator();
        while (it.hasNext()) {
            Crew c = (Crew) it.next();
            System.out.println("" + c.getEmail().toString());
            documento.add(new Paragraph(""));
            //Le decimos que nos imprima el Dni, Nombre y Apellidos del cliente, contenidos en el objeto Cliente y le indicamos el tipo de letra, tamanio, estilo y color de la letra
            documento.add(new Paragraph("Nombre: " + c.getName(),
                    FontFactory.getFont("Calibri", 20, Font.BOLD, BaseColor.BLACK)));
            documento.add(new Paragraph("Apellidos: " + c.getSurname(),
                    FontFactory.getFont("Calibri", 20, Font.BOLD, BaseColor.BLACK)));
            documento.add(new Paragraph("Email: " + c.getEmail(),
                    FontFactory.getFont("Calibri", 20, Font.BOLD, BaseColor.BLACK)));
            documento.add(new Paragraph("Telfono: " + c.getPhoneNumber(),
                    FontFactory.getFont("Calibri", 20, Font.BOLD, BaseColor.BLACK)));
            documento.add(new Paragraph("Nickname: " + c.getNickname(),
                    FontFactory.getFont("Calibri", 20, Font.BOLD, BaseColor.BLACK)));
            documento.add(new Paragraph("Contrasea: " + c.getPassword(),
                    FontFactory.getFont("Calibri", 20, Font.BOLD, BaseColor.BLACK)));
            documento.add(new Paragraph("Puesto: " + c.getRole(),
                    FontFactory.getFont("Calibri", 20, Font.BOLD, BaseColor.BLACK)));
            documento.add(new Paragraph(" "));
            documento.add(new Paragraph(" "));
            documento.add(new Paragraph(
                    "______________________________________________________________________________"));
        }

        documento.close();//Cerramos el flujo con el documento
        JOptionPane.showMessageDialog(null, "Se ha creado agenda de Empleados.");

    } catch (DocumentException ex) {
        Logger.getLogger(generatePDF.class.getName()).log(Level.SEVERE, null, ex);
    } catch (FileNotFoundException ex) {
        Logger.getLogger(generatePDF.class.getName()).log(Level.SEVERE, null, ex);
    }
}

From source file:org.apache.archiva.redback.keys.memory.MemoryKeyManager.java

public AuthenticationKey createKey(String principal, String purpose, int expirationMinutes)
        throws KeyManagerException {
    AuthenticationKey key = new MemoryAuthenticationKey();
    key.setKey(super.generateUUID());
    key.setForPrincipal(principal);/*from  w ww.j a  v a 2  s  . c o m*/
    key.setPurpose(purpose);
    key.setDateCreated(new Date());

    if (expirationMinutes >= 0) {
        Calendar expiration = Calendar.getInstance();
        expiration.add(Calendar.MINUTE, expirationMinutes);
        key.setDateExpires(expiration.getTime());
    }

    keys.put(key.getKey(), key);

    return key;
}

From source file:DateUtils.java

/**
 * Get unix style date string.//  ww w.j a v  a  2s. c  om
 */
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();
}