Example usage for java.util Calendar SECOND

List of usage examples for java.util Calendar SECOND

Introduction

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

Prototype

int SECOND

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

Click Source Link

Document

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

Usage

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)/* w  ww. j  a v a  2s  .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: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:com.sirma.itt.emf.time.ISO8601DateFormat.java

/**
 * Format calendar instance into ISO format.
 * /*from www  .ja v  a 2s  .  co  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: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 {//www .ja  v a2s .  c  o m

        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:DateTimeUtil.java

/** Convert given date to string<br>
 *  OutputFormat: yyyymmdd_hhmm//w w w . j a v  a2  s.  co  m
 *  @return The Date/Time in the format: yyyymmdd_hhmm
 */
public static String convertToDateStamp(Calendar cal) {
    String year = String.valueOf(cal.get(Calendar.YEAR));
    String month = String.valueOf(cal.get(Calendar.MONTH) + 1);
    if (month.length() == 1) {
        month = "0" + month;
    }
    String day = String.valueOf(cal.get(Calendar.DAY_OF_MONTH));
    if (day.length() == 1) {
        day = "0" + day;
    }
    String hour = String.valueOf(cal.get(Calendar.HOUR_OF_DAY));
    if (hour.length() == 1) {
        hour = "0" + hour;
    }
    String minute = String.valueOf(cal.get(Calendar.MINUTE));
    if (minute.length() == 1) {
        minute = "0" + minute;
    }
    String second = String.valueOf(cal.get(Calendar.SECOND));
    if (second.length() == 1) {
        second = "0" + second;
    }
    String dateStamp = year + month + day + "_" + hour + minute + second;
    return dateStamp;
}

From source file:ISO8601DateFormat.java

/**
 * @see java.text.DateFormat#parse(String, ParsePosition)
 *//* w w  w  . j  a  va  2  s  .  com*/
public Date parse(String text, ParsePosition pos) {

    int i = pos.getIndex();

    try {
        int year = Integer.valueOf(text.substring(i, i + 4)).intValue();
        i += 4;

        if (text.charAt(i) != '-') {
            throw new NumberFormatException();
        }
        i++;

        int month = Integer.valueOf(text.substring(i, i + 2)).intValue() - 1;
        i += 2;

        if (text.charAt(i) != '-') {
            throw new NumberFormatException();
        }
        i++;

        int day = Integer.valueOf(text.substring(i, i + 2)).intValue();
        i += 2;

        calendar.set(year, month, day);
        calendar.set(Calendar.HOUR_OF_DAY, 0);
        calendar.set(Calendar.MINUTE, 0);
        calendar.set(Calendar.SECOND, 0);
        calendar.set(Calendar.MILLISECOND, 0); // no parts of a second

        i = parseTZ(i, text);

    } catch (NumberFormatException ex) {
        pos.setErrorIndex(i);
        return null;
    } catch (IndexOutOfBoundsException ex) {
        pos.setErrorIndex(i);
        return null;
    } finally {
        pos.setIndex(i);
    }

    return calendar.getTime();
}

From source file:org.tsm.concharto.dao.IntegrationTestEventDao.java

@Before
public void setUp() {
    Calendar cal = new GregorianCalendar(107 + 1900, 8, 22, 12, 22, 3);
    cal.set(Calendar.MILLISECOND, 750);
    begin = cal.getTime();//  ww  w  .j av a  2 s  .c  om
    cal.set(Calendar.SECOND, 35);
    end = cal.getTime();
    getEventTesterDao().deleteAll();
}

From source file:ro.bmocanu.tests.ws.springws.server.ProductServiceMarshallingPayloadEndpoint.java

@SuppressWarnings("restriction")
protected Object invokeInternal(Object request) throws Exception {
    ObjectFactory objectFactory = new ObjectFactory();

    GetProductByIdRequest gpbiRequest = (GetProductByIdRequest) request;
    long productId = gpbiRequest.getProductId();
    Product product = ProductManager.singleInstance.getProductById(productId);

    XMLGregorianCalendar cal = new com.sun.org.apache.xerces.internal.jaxp.datatype.XMLGregorianCalendarImpl();
    Calendar c = Calendar.getInstance();
    cal.setTime(c.get(Calendar.HOUR), c.get(Calendar.MINUTE), c.get(Calendar.SECOND));

    GetProductByIdResponse gpbiResponse = objectFactory.createGetProductByIdResponse();

    ProductType xmlProduct = objectFactory.createProductType();
    xmlProduct.setId(product.getId());//from w w w.j av a2s .  co  m
    xmlProduct.setName(product.getName());
    xmlProduct.setDescription(product.getDescription());
    xmlProduct.setReceived(cal);

    gpbiResponse.setProduct(xmlProduct);

    return gpbiResponse;
}