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 void main(String[] a) {
    Date date = new Date();
    GregorianCalendar calendar = new GregorianCalendar();
    calendar.setTime(date);//from  w  w  w.  j a  v  a2  s.c  o  m
}

From source file:Main.java

public static void main(String[] args) {
    GregorianCalendar gc = new GregorianCalendar();
    // current year value
    int year = gc.get(Calendar.YEAR);
    System.out.println(year);/* w  w  w.  jav  a2  s . c o m*/
    // current month value
    int month = gc.get(Calendar.MONTH);
    System.out.println(month);
    // day of month
    int day = gc.get(Calendar.DAY_OF_MONTH);
    System.out.println(day);
    // hour value
    int hour = gc.get(Calendar.HOUR);
    System.out.println(hour);
    // minute value
    int minute = gc.get(Calendar.MINUTE);
    System.out.println(minute);
    // second values
    int second = gc.get(Calendar.SECOND);
    System.out.println(second);
}

From source file:Main.java

public static void main(String[] argv) throws Exception {

    GregorianCalendar newCal = new GregorianCalendar();
    int day = newCal.get(Calendar.DAY_OF_WEEK);

    newCal = new GregorianCalendar();
    newCal.set(1997, 2, 1, 0, 0, 0);//from   w ww  . j a va 2s .  c om
    newCal.setTime(newCal.getTime());
    day = newCal.get(Calendar.DAY_OF_WEEK);

}

From source file:Main.java

public static void main(String[] args) {
    int dayOfWeek = Calendar.SUNDAY;
    Calendar cal = new GregorianCalendar();
    cal.set(2015, 0, 1, 0, 0);//from  w w  w  .java  2 s  .  c o m
    cal.set(Calendar.DAY_OF_WEEK, dayOfWeek);
    while (cal.get(Calendar.YEAR) == 2015) {
        System.out.println(cal.getTime());
        cal.add(Calendar.DAY_OF_MONTH, 7);
    }
}

From source file:Main.java

public static void main(String[] args) {
    // ZonedDateTime from specific Calendar
    ZonedDateTime gregorianCalendarDateTime = new GregorianCalendar().toZonedDateTime();
    System.out.println(gregorianCalendarDateTime);
}

From source file:Main.java

public static void main(String[] argv) throws Exception {
    // Create a Calendar object with the local time zone
    Calendar local = new GregorianCalendar();
    local.set(Calendar.HOUR_OF_DAY, 10); // 0..23
    local.set(Calendar.MINUTE, 0);
    local.set(Calendar.SECOND, 0);

}

From source file:Main.java

public static void main(String[] args) {

    GregorianCalendar cal1 = (GregorianCalendar) GregorianCalendar.getInstance();

    // create a second calendar
    GregorianCalendar cal2 = new GregorianCalendar();

    // clone cal1 to cal2
    cal2 = (GregorianCalendar) cal1.clone();

    // print cal2
    System.out.println(cal2.getTime());

}

From source file:Main.java

public static void main(String[] args) {
    Date date = Date.valueOf("2015-12-25");
    System.out.println(date);//from   w  w  w.  j a va 2s  .  c om

    Calendar cal = new GregorianCalendar();
    cal.setTime(date);
    System.out.println(cal.getTime());
}

From source file:MainClass.java

public static void main(String args[]) {
    GregorianCalendar today = new GregorianCalendar();

    int todayMonth = today.get(Calendar.MONTH);

    int todayDayOfMonth = today.get(Calendar.DAY_OF_MONTH);

    int todayYear = today.get(Calendar.YEAR);

    int todayDayOfYear = today.get(Calendar.DAY_OF_YEAR);

    int numDays;/*from  ww  w  . j  a v a2 s . com*/
    if (todayMonth == 11 && todayDayOfMonth > 25) {
        GregorianCalendar xmas = new GregorianCalendar(todayYear + 1, 11, 25);
        int xmasDayOfYear = xmas.get(Calendar.DAY_OF_YEAR);
        numDays = xmasDayOfYear + 31 - todayDayOfMonth;
    } else {
        GregorianCalendar xmas = new GregorianCalendar(todayYear, 11, 25);
        int xmasDayOfYear = xmas.get(Calendar.DAY_OF_YEAR);
        numDays = xmasDayOfYear - todayDayOfYear;
    }

    System.out.println("The number of days till Christmas is " + numDays);
}

From source file:Main.java

public static void main(String[] args) {
    // Get the current date in the system default time zone
    GregorianCalendar currentDate = new GregorianCalendar();
    System.out.println(currentDate.getTime());
    // Get GregorianCalendar object representing March 21, 2014 07:30:45 AM
    GregorianCalendar someDate = new GregorianCalendar(2014, Calendar.MARCH, 21, 7, 30, 45);
    System.out.println(someDate.getTime());
    // Get Indian time zone, which is GMT+05:30
    TimeZone indianTZ = TimeZone.getTimeZone("GMT+05:30");
    GregorianCalendar indianDate = new GregorianCalendar(indianTZ);
    System.out.println(indianDate.getTime());
}