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(int year, int month, int dayOfMonth, int hourOfDay, int minute) 

Source Link

Document

Constructs a GregorianCalendar with the given date and time set for the default time zone with the default locale.

Usage

From source file:Main.java

public static void main(String[] args) {

    GregorianCalendar cal = new GregorianCalendar(2013, 9, 9, 22, 23);

    System.out.println(cal.getTime());

}

From source file:Main.java

public static void main(String[] av) {
    Date d1 = new GregorianCalendar(2000, 11, 31, 23, 59).getTime();

    Date today = new Date();

    long diff = today.getTime() - d1.getTime();

    System.out.println(//w  w w . ja  v a 2  s.  c o m
            "The 21st century (up to " + today + ") is " + (diff / (1000 * 60 * 60 * 24)) + " days old.");
}

From source file:MainClass.java

public static void main(String[] a) throws Exception {
    Date d1 = new GregorianCalendar(2000, 11, 31, 23, 59).getTime();

    Date today = new Date();

    long diff = today.getTime() - d1.getTime();

    System.out.println(/*from   w  w  w. j a va2s .  c o m*/
            "The 21st century (up to " + today + ") is " + (diff / (1000 * 60 * 60 * 24)) + " days old.");
}

From source file:DateDiff.java

public static void main(String[] av) {
    /** The date at the end of the last century */
    Date d1 = new GregorianCalendar(2000, 11, 31, 23, 59).getTime();

    /** Today's date */
    Date today = new Date();

    // Get msec from each, and subtract.
    long diff = today.getTime() - d1.getTime();

    System.out.println(/*from  www  . java 2s.  c o m*/
            "The 21st century (up to " + today + ") is " + (diff / (1000 * 60 * 60 * 24)) + " days old.");
}

From source file:Main.java

public static Date getDate(int year, int month, int day, int hour, int minute) {
    GregorianCalendar calendar = new GregorianCalendar(year, month - 1, day, hour, minute);
    return calendar.getTime();
}

From source file:com.mycompany.app.VariousTest.java

public static void timeDifference() {
    Calendar t1 = new GregorianCalendar(2014, 06, 05, 6, 0);
    Calendar t2 = new GregorianCalendar(2014, 06, 05, 8, 59);

    int minutes = minutesDiff(new Date(t1.getTimeInMillis()), new Date(t2.getTimeInMillis()));
    System.out.println("Minutes diff: " + minutes);
}

From source file:com.trenako.repositories.mongo.CommentsRepositoryTests.java

@Override
void initRepository(MongoTemplate mongo) {
    repo = new CommentsRepositoryImpl(mongo);

    // mocking the current timestamp value
    ((CommentsRepositoryImpl) repo).setCurrentTimestamp(new GregorianCalendar(2012, 6, 1, 10, 0).getTime());
}

From source file:com.trenako.repositories.mongo.CollectionsRepositoryTests.java

@Override
void initRepository(MongoTemplate mongo) {
    repo = new CollectionsRepositoryImpl(mongo);

    // mocking the current timestamp value
    ((CollectionsRepositoryImpl) repo).setCurrentTimestamp(new GregorianCalendar(2012, 6, 1, 10, 0).getTime());
}

From source file:de.tor.tribes.ui.components.TimePicker.java

public Date getTime() {
    Date d = new GregorianCalendar(0, 0, 0, pHour, pMinute).getTime();
    d = DateUtils.setSeconds(d, 0);// w  w w  . jav  a  2s .c  om
    d = DateUtils.setMilliseconds(d, 0);
    return d;
}

From source file:groovyx.gaelyk.graelyk.cast.StructuredDateEditor.java

public Object assemble(Class type, Map fieldValues) throws IllegalArgumentException {
    if (!fieldValues.containsKey("year")) {
        throw new IllegalArgumentException("Can't populate a date without a year");
    }//from   w  ww  .  ja v a  2s.co m

    String yearString = (String) fieldValues.get("year");
    int year;

    try {
        if (StringUtils.isBlank(yearString)) {
            throw new IllegalArgumentException("Can't populate a date without a year");
        } else {
            year = Integer.parseInt(yearString);
        }

        int month = getIntegerValue(fieldValues, "month", 1);
        int day = getIntegerValue(fieldValues, "day", 1);
        int hour = getIntegerValue(fieldValues, "hour", 0);
        int minute = getIntegerValue(fieldValues, "minute", 0);

        Calendar c = new GregorianCalendar(year, month - 1, day, hour, minute);
        if (type == Date.class) {
            return c.getTime();
        } else if (type == java.sql.Date.class) {
            return new java.sql.Date(c.getTime().getTime());
        }
        return c;
    } catch (NumberFormatException nfe) {
        throw new IllegalArgumentException(
                "Unable to parse structured date from request for date [\"+propertyName+\"]\"");
    }
}