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 long getMonthTimeMilis(long l, int i) {
    Date date = new Date(l);
    GregorianCalendar gregoriancalendar = new GregorianCalendar();
    gregoriancalendar.set(date.getYear() + 1900, i, 1, 0, 0, 0);
    gregoriancalendar.set(14, 0);//from   w  w  w . j a  va 2s  .c o  m
    return gregoriancalendar.getTimeInMillis();
}

From source file:MainClass.java

public static Timestamp makeTimestamp(int year, int month, int day, int hour, int minute, int second,
        int millisecond) {
    Calendar cal = new GregorianCalendar();
    cal.set(Calendar.YEAR, year);
    cal.set(Calendar.MONTH, month - 1);
    cal.set(Calendar.DATE, day);/*  w w w  .j  a  v  a2 s.c  om*/
    cal.set(Calendar.HOUR_OF_DAY, hour);
    cal.set(Calendar.MINUTE, minute);
    cal.set(Calendar.SECOND, second);
    cal.set(Calendar.MILLISECOND, millisecond);

    // now convert GregorianCalendar object to Timestamp object
    return new Timestamp(cal.getTimeInMillis());
}

From source file:Main.java

public static Date nextDay(Date date) {
    Calendar calendar = new GregorianCalendar();
    calendar.setTime(date);/*  w w w.  j  a v  a2 s  .  co  m*/
    calendar.add(calendar.DATE, 1);
    date = calendar.getTime();
    return date;
}

From source file:Main.java

/**
 * Remove the time of a date value/*from www. j a v a  2 s . co m*/
 *
 * @param date Date to remove the time part
 * @return A date with its time set to 00:00:00
 */
public static Date removeTime(Date date) {
    GregorianCalendar gc = new GregorianCalendar();
    gc.setTime(date);
    gc.set(Calendar.HOUR_OF_DAY, 0);
    gc.set(Calendar.MINUTE, 0);
    gc.set(Calendar.SECOND, 0);
    gc.set(Calendar.MILLISECOND, 0);
    return gc.getTime();
}

From source file:Main.java

public static XMLGregorianCalendar getXmlGregorianCalendarFromDate(Date date) {

    GregorianCalendar cal = new GregorianCalendar();
    cal.setTime(date);/*from  w w w . j av a  2  s .c om*/

    XMLGregorianCalendar f = null;
    try {
        f = DatatypeFactory.newInstance().newXMLGregorianCalendar(cal);
    } catch (DatatypeConfigurationException e) {
        e.printStackTrace();
    }

    return f;
}

From source file:Main.java

public static String getCurrentTimeStampHHMM() {
    Calendar cal = new GregorianCalendar();
    return makeTimeString(cal.get(Calendar.HOUR_OF_DAY), 2) + ":" + makeTimeString(cal.get(Calendar.MINUTE), 2);
}

From source file:Main.java

public static String getCurrentTimeStampYYYY() {
    Calendar cal = new GregorianCalendar();
    return makeTimeString(cal.get(Calendar.YEAR), 4);
}

From source file:Main.java

public static String getCurrentTimeStamp() {
    Calendar cal = new GregorianCalendar();
    return makeTimeString(cal.get(Calendar.DAY_OF_MONTH), 2) + "."
            + makeTimeString(cal.get(Calendar.MONTH) + 1, 2) + "." + makeTimeString(cal.get(Calendar.YEAR), 4)
            + " " + makeTimeString(cal.get(Calendar.HOUR_OF_DAY), 2) + ":"
            + makeTimeString(cal.get(Calendar.MINUTE), 2) + ":" + makeTimeString(cal.get(Calendar.SECOND), 2);
}

From source file:Main.java

public static String getTimeStamp(long l) {
    Calendar cal = new GregorianCalendar();
    cal.setTimeInMillis(l);/*  w  w  w .j  a v  a  2 s.  c  o m*/
    return makeTimeString(cal.get(Calendar.DAY_OF_MONTH), 2) + "."
            + makeTimeString(cal.get(Calendar.MONTH) + 1, 2) + "." + makeTimeString(cal.get(Calendar.YEAR), 4)
            + " " + makeTimeString(cal.get(Calendar.HOUR_OF_DAY), 2) + ":"
            + makeTimeString(cal.get(Calendar.MINUTE), 2) + ":" + makeTimeString(cal.get(Calendar.SECOND), 2);
}

From source file:Main.java

public static String getCurrentTimeStampHHMMSS() {
    Calendar cal = new GregorianCalendar();
    return makeTimeString(cal.get(Calendar.HOUR_OF_DAY), 2) + ":" + makeTimeString(cal.get(Calendar.MINUTE), 2)
            + ":" + makeTimeString(cal.get(Calendar.SECOND), 2);
}