Example usage for java.util GregorianCalendar GregorianCalendar

List of usage examples for java.util GregorianCalendar GregorianCalendar

Introduction

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

Prototype

public GregorianCalendar() 

Source Link

Document

Constructs a default GregorianCalendar using the current time in the default time zone with the default Locale.Category#FORMAT FORMAT locale.

Usage

From source file:Main.java

public static Date getDateMinuteBefore(Date originalDate, int minutes) {
    Calendar cal = new GregorianCalendar();
    cal.setTime(originalDate);//from  ww w .j  ava 2 s  . c om
    cal.add(Calendar.MINUTE, minutes * -1);
    return cal.getTime();
}

From source file:Main.java

public static XMLGregorianCalendar timestampToXMLGregorianCalendar(Timestamp t) {
    if (t == null) {
        return null;
    }//from w  w w .j a  v  a2 s . c  o  m

    GregorianCalendar gc = new GregorianCalendar();
    gc.setTimeInMillis(t.getTime());
    try {
        return DatatypeFactory.newInstance().newXMLGregorianCalendar(gc);
    } catch (DatatypeConfigurationException ex) {
        return null;
    }
}

From source file:Main.java

public static Date setDateTime(Date originalDate, int hour, int minute, int second) {
    Calendar cal = new GregorianCalendar();
    cal.setTime(originalDate);// w w  w  . j av  a 2s.  c o m
    cal.set(Calendar.HOUR, hour);
    cal.set(Calendar.MINUTE, minute);
    cal.set(Calendar.SECOND, second);
    cal.set(Calendar.MILLISECOND, 0);
    return cal.getTime();
}

From source file:Main.java

public final static Timestamp getTodayMidnight() {
    GregorianCalendar calendar = new GregorianCalendar();
    calendar.set(GregorianCalendar.HOUR_OF_DAY, 0);
    calendar.set(GregorianCalendar.MINUTE, 0);
    calendar.set(GregorianCalendar.SECOND, 0);
    calendar.set(GregorianCalendar.MILLISECOND, 0);
    return new Timestamp(calendar.getTimeInMillis());
}

From source file:Main.java

public static String DateToXSD_DateTime(Date d) {
    DatatypeFactory f;//  w  ww .j  a v  a  2  s. c o  m
    try {
        f = DatatypeFactory.newInstance();
    } catch (DatatypeConfigurationException e) {
        throw new RuntimeException(e);
    }

    GregorianCalendar cal = new GregorianCalendar();
    cal.setTime(d);

    return f.newXMLGregorianCalendar(cal).toXMLFormat();
}

From source file:Main.java

public static Date getDateObj() {
    Calendar c = new GregorianCalendar();
    return c.getTime();
}

From source file:Main.java

public static XMLGregorianCalendar toXMLGregorianCalendar(Timestamp t) {
    if (t == null)
        return null;
    GregorianCalendar calendar = new GregorianCalendar();
    calendar.setTime(t);//from   www.j  a v  a 2s . com
    return newInstance.newXMLGregorianCalendar(calendar);
}

From source file:com.aes.touresbalon.touresbalonoms.utilities.OmsUtil.java

public static XMLGregorianCalendar stringToXMLGreogrianCalendar(Date fecha)
        throws ParseException, DatatypeConfigurationException {
    //        DateFormat formatter = new SimpleDateFormat("yyyyMMdd");
    //        Date fechaUtil = formatter.parse(fecha);
    GregorianCalendar gc = new GregorianCalendar();
    DatatypeFactory df = DatatypeFactory.newInstance();
    gc.setTimeInMillis(fecha.getTime());
    return df.newXMLGregorianCalendar(gc);
}

From source file:Main.java

public static XMLGregorianCalendar toGregorianCaldendar(final Date date) {
    if (date != null) {
        GregorianCalendar c = new GregorianCalendar();
        c.setTime(date);/*from   w  ww .j  a  v  a  2 s.  com*/
        try {
            return DatatypeFactory.newInstance().newXMLGregorianCalendar(c);
        } catch (DatatypeConfigurationException e) {
            throw new RuntimeException(e);
        }
    }

    return null;
}

From source file:Main.java

public static void end() {
    GregorianCalendar endtime = new GregorianCalendar();
    long difference = endtime.getTimeInMillis() - starttime.getTimeInMillis();
    int mins = (int) Math.floor(difference / 60000.0);
    double secs = (difference / 1000.0 - mins * 60.0);
    System.out.println(mins + " m " + secs + " s");
}