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, int second) 

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, 52);

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

}

From source file:Main.java

public static void main(String[] args) {
    GregorianCalendar gc = new GregorianCalendar(2014, 1, 11, 15, 45, 50);
    LocalDate ld = gc.toZonedDateTime().toLocalDate();
    System.out.println("Local  Date: " + ld);

    LocalTime lt = gc.toZonedDateTime().toLocalTime();
    System.out.println("Local Time:  " + lt);

    LocalDateTime ldt = gc.toZonedDateTime().toLocalDateTime();
    System.out.println("Local DateTime:  " + ldt);

    OffsetDateTime od = gc.toZonedDateTime().toOffsetDateTime();
    System.out.println("Offset  Date: " + od);

    OffsetTime ot = gc.toZonedDateTime().toOffsetDateTime().toOffsetTime();
    System.out.println("Offset Time:  " + ot);

    ZonedDateTime zdt = gc.toZonedDateTime();
    System.out.println("Zoned DateTime:  " + zdt);

    ZoneId zoneId = zdt.getZone();
    TimeZone timeZone = TimeZone.getTimeZone(zoneId);
    System.out.println("Zone ID:  " + zoneId);
    System.out.println("Time Zone ID:  " + timeZone.getID());

    GregorianCalendar gc2 = GregorianCalendar.from(zdt);
    System.out.println("Gregorian  Calendar: " + gc2.getTime());
}

From source file:DateUtilsV1.java

 public static void main(String args[]) {
   GregorianCalendar calendar = new GregorianCalendar(1974, 5, 25, 6, 30, 30);
   Date date = calendar.getTime();

   System.err.println("Original Date: " + date);
   System.err.println("Rounded Date: " + DateUtils.round(date, Calendar.HOUR));
   System.err.println("Truncated Date: " +   DateUtils.truncate(date, Calendar.MONTH));

   Iterator itr = DateUtils.iterator(date, DateUtils.RANGE_WEEK_MONDAY);

   while(itr.hasNext()) {
      System.err.println(((Calendar)itr.next()).getTime());
   }//from w  w  w.  j  av  a  2 s .c  o  m
}

From source file:Main.java

public static Date getTimeFrom(int year, int month, int day, int hour, int minute, int second) {
    Calendar calendar = new GregorianCalendar(year, month, day, hour, minute, second);
    calendar.setTimeZone(TimeZone.getTimeZone("UTC"));
    return calendar.getTime();
}

From source file:Main.java

public static GregorianCalendar getCalendarFromString(String theString) {
    String[] formatSplit = theString.split("T");
    String[] dateSplit = formatSplit[0].split("-");
    String[] timeSplit = formatSplit[1].split(":");
    int year = Integer.parseInt(dateSplit[0]);
    int month = Integer.parseInt(dateSplit[1]);
    int day = Integer.parseInt(dateSplit[2]);
    int hour = Integer.parseInt(timeSplit[0]);
    int minute = Integer.parseInt(timeSplit[1]);
    int second = Integer.parseInt(timeSplit[2]);
    GregorianCalendar result = new GregorianCalendar(year, month, day, hour, minute, second);
    return result;
}

From source file:net.darkmist.clf.LogParserTest.java

private static Date mkLogTimeAsDate() {
    GregorianCalendar cal = new GregorianCalendar(2007, 5, 5, 8, 9, 10);
    cal.setTimeZone(TimeZone.getTimeZone("GMT-1"));
    return cal.getTime();
}

From source file:net.darkmist.clf.LogEntryTest.java

private static final Date mkStaticDate() {
    GregorianCalendar cal = new GregorianCalendar(2007, 5, 5, 8, 9, 10);
    cal.setTimeZone(TimeZone.getTimeZone("GMT-1"));
    return cal.getTime();
}

From source file:Main.java

/**
 * Parses a date/time string from within an XMLTV stream.  Only the local
 * time part of the value is parsed. Timezone specifications are ignored.
 * /*  w  w  w. j a  v  a 2  s  .com*/
 * @param str the string
 * @param convertTimezone true to convert date/time values to local time
 * @return the date/time value as a Calendar object
 */
public static Calendar parseDateTime(String str, boolean convertTimezone) {
    // Format looks like: 20111209060000 +1100
    if (str == null)
        return null;
    int year = parseField(str, 0, 4);
    int month = parseField(str, 4, 2);
    int day = parseField(str, 6, 2);
    int hour = parseField(str, 8, 2);
    int minute = parseField(str, 10, 2);
    int second = parseField(str, 12, 2);
    if (convertTimezone) {
        if (cachedTimeZone == null) {
            cachedTimeZone = TimeZone.getDefault();
            cachedOffset = cachedTimeZone.getOffset(System.currentTimeMillis());
        }
        int tz = parseTZField(str, 14);
        if (tz != cachedOffset) {
            Calendar calendar = new GregorianCalendar(year, month - 1, day, hour, minute, second);
            calendar.add(Calendar.MILLISECOND, cachedOffset - tz);
            return calendar;
        }
    }
    return new GregorianCalendar(year, month - 1, day, hour, minute, second);
}

From source file:it.f2informatica.webapp.utils.PeriodParser.java

private Date _resolveDateByMonthAndYear(String month, String year) {
    int yearInt = Integer.parseInt(year);
    int monthInt = Integer.parseInt(month);
    return new GregorianCalendar(yearInt, monthInt, 1, 0, 0, 0).getTime();
}

From source file:au.id.hazelwood.xmltvguidebuilder.utils.DateTimeUtilsUnitTest.java

@Test
public void testToDateTime() throws Exception {
    Calendar calendar = new GregorianCalendar(2010, 0, 8, 9, 20, 0);
    assertEquals(new DateTime(2010, 1, 8, 9, 20, 0, 0).getMillis(),
            DateTimeUtils.toDateTime(calendar).getMillis());
}