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

GregorianCalendar(TimeZone zone, Locale locale, boolean flag) 

Source Link

Document

Constructs an empty GregorianCalendar.

Usage

From source file:GregCalDemo.java

public static void main(String[] av) {
    //+//from  w w w. j ava  2 s .  co m
    GregorianCalendar d1 = new GregorianCalendar(1986, 04, 05); // May 5
    GregorianCalendar d2 = new GregorianCalendar(); // today
    Calendar d3 = Calendar.getInstance(); // today

    System.out.println("It was then " + d1.getTime());
    System.out.println("It is now " + d2.getTime());
    System.out.println("It is now " + d3.getTime());
    d3.set(Calendar.YEAR, 1915);
    d3.set(Calendar.MONTH, Calendar.APRIL);
    d3.set(Calendar.DAY_OF_MONTH, 12);
    System.out.println("D3 set to " + d3.getTime());
    //-
}

From source file:Main.java

public static void main(String[] args) {

    // create two calendar at the different dates
    Calendar cal1 = new GregorianCalendar(2015, 8, 15);
    Calendar cal2 = new GregorianCalendar(2013, 1, 02);

    // compare the time values represented by two calendar objects.
    int i = cal1.compareTo(cal2);

    // return positive value if equals else return negative value
    System.out.println("The result is :" + i);

    // compare again but with the two calendars swapped
    int j = cal2.compareTo(cal1);

    // return positive value if equals else return negative value
    System.out.println("The result is :" + j);

}

From source file:Main.java

public static void main(String[] args) {

    Calendar cal = Calendar.getInstance();

    // specify a date for one of them
    Calendar cal2 = new GregorianCalendar(2013, 06, 29);

    // compare the two calendars.
    boolean b = cal.equals(cal2);

    // print result
    System.out.println("Calendars are equal :" + b);
}

From source file:Main.java

public static void main(String[] args) {
    int year = 2015;
    int month = 4;

    SimpleDateFormat format = new SimpleDateFormat("dd-MM-yyyy");

    GregorianCalendar calendar = new GregorianCalendar(year, month, 1);

    while (calendar.get(GregorianCalendar.MONTH) == month) {
        String dateString = format.format(calendar.getTime());
        System.out.println(dateString);

        calendar.add(GregorianCalendar.DATE, 1);
    }/*from   www. ja v a2s .  c o  m*/
}

From source file:Main.java

public static void main(String args[]) {

    Calendar calendar1 = Calendar.getInstance();
    int currentDayOfYear = calendar1.get(Calendar.DAY_OF_YEAR);

    int year = calendar1.get(Calendar.YEAR);

    Calendar calendar2 = new GregorianCalendar(year, 11, 31);
    int dayDecember31 = calendar2.get(Calendar.DAY_OF_YEAR);

    int days = dayDecember31 - currentDayOfYear;
    System.out.println(days + " days remain in current year");
}

From source file:Main.java

public static void main(String[] argv) throws Exception {
    SpinnerDateModel dateModel = new SpinnerDateModel();
    JSpinner spinner = new JSpinner(dateModel);

    Calendar calendar = new GregorianCalendar(2000, Calendar.JANUARY, 1);
    spinner.setValue(calendar.getTime());
}

From source file:MainClass.java

public static void main(String[] args) {

    GregorianCalendar birthdate = new GregorianCalendar(1999, 1, 1);
    GregorianCalendar today = new GregorianCalendar(); // Today's date
    GregorianCalendar birthday = new GregorianCalendar(today.get(YEAR), birthdate.get(MONTH),
            birthdate.get(DATE));/* w ww. j  ava2 s  .c  om*/
    int age = today.get(today.YEAR) - birthdate.get(YEAR);
    String[] weekdays = new DateFormatSymbols().getWeekdays(); // Get day names
    System.out.println("You were born on a " + weekdays[birthdate.get(DAY_OF_WEEK)]);
    System.out.println("This year you " + (birthday.after(today) ? " will be " : "are ") + age + " years old.");
    System.out
            .println("In " + today.get(YEAR) + " your birthday " + (today.before(birthday) ? "will be" : "was")
                    + " on a " + weekdays[birthday.get(DAY_OF_WEEK)] + ".");
}

From source file:MainClass.java

public static void main(String args[]) {

    Calendar calendar1 = Calendar.getInstance();
    int doy1 = calendar1.get(Calendar.DAY_OF_YEAR);

    int year = calendar1.get(Calendar.YEAR);

    Calendar calendar2 = new GregorianCalendar(year, 11, 31);
    int doy2 = calendar2.get(Calendar.DAY_OF_YEAR);

    int days = doy2 - doy1;
    System.out.println(days + " days remain in current year");
}

From source file:BeanUtilsExampleV2.java

  public static void main(String args[]) throws Exception {
    BeanUtilsExampleV2 diff = new BeanUtilsExampleV2();
    Movie movieBean = diff.prepareData();

    // create a new Movie with the same properties
    Movie newMovieBean = new Movie();
    BeanUtils.copyProperties(newMovieBean, movieBean);
    // Movie newMovieBean = (Movie)BeanUtils.cloneBean(movieBean);

    // change its title
    BeanUtils.setProperty(newMovieBean, "title", "Quills");

    // and date/*from   w  w  w  . java 2 s .c  om*/
    BeanUtils.setProperty(
       newMovieBean,
       "dateOfRelease",
       new GregorianCalendar(2000, 0, 1).getTime());

    // and director name
    BeanUtils.setProperty(newMovieBean, "director.name", "Philip Kaufman");

    // and director's home number
    BeanUtils.setProperty(
       newMovieBean,
       "director.contactNumber(Home)",
       "3349084333");

    System.err.println(BeanUtils.getProperty(movieBean, "title"));
    System.err.println(BeanUtils.getProperty(movieBean, "director.name"));
    System.err.println(BeanUtils.getProperty(
       newMovieBean,
       "director.contactNumber(Home)"));
}

From source file:PairTest2.java

public static void main(String[] args) {
    GregorianCalendar[] birthdays = { new GregorianCalendar(1906, Calendar.DECEMBER, 9), // G. Hopper
            new GregorianCalendar(1815, Calendar.DECEMBER, 10), // A. Lovelace
            new GregorianCalendar(1903, Calendar.DECEMBER, 3), // J. von Neumann
            new GregorianCalendar(1910, Calendar.JUNE, 22), // K. Zuse
    };//ww w .  ja  va 2s.c o m
    Pair<GregorianCalendar> mm = ArrayAlg.minmax(birthdays);
    System.out.println("min = " + mm.getFirst().getTime());
    System.out.println("max = " + mm.getSecond().getTime());
}