Example usage for java.util GregorianCalendar getTime

List of usage examples for java.util GregorianCalendar getTime

Introduction

In this page you can find the example usage for java.util GregorianCalendar getTime.

Prototype

public final Date getTime() 

Source Link

Document

Returns a Date object representing this Calendar's time value (millisecond offset from the Epoch").

Usage

From source file:Main.java

public static void main(String[] args) {

    GregorianCalendar cal = (GregorianCalendar) GregorianCalendar.getInstance();

    // print the current date and time
    System.out.println(cal.getTime());

    // roll 2 months
    cal.roll(GregorianCalendar.MONTH, 2);
    System.out.println("Date:" + cal.getTime());

    // roll 5 year backwards
    cal.roll(GregorianCalendar.YEAR, -5);
    System.out.println("Date:" + cal.getTime());

}

From source file:Main.java

public static void main(String[] args) {

    GregorianCalendar cal = (GregorianCalendar) GregorianCalendar.getInstance();

    // print the current date and time
    System.out.println(cal.getTime());

    // roll a month
    cal.roll(GregorianCalendar.MONTH, true);
    System.out.println("Date:" + cal.getTime());

    // roll a year backwards
    cal.roll(GregorianCalendar.YEAR, false);
    System.out.println("Date:" + cal.getTime());

}

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) {
    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);
    }/* w  w w  .  ja v a2  s.c o m*/
}

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);//w  w w  .j a  v a 2s .  c o  m
    newCal.setTime(newCal.getTime());
    day = newCal.get(Calendar.DAY_OF_WEEK);

}

From source file:Main.java

public static void main(String[] args) {

    GregorianCalendar cal = new GregorianCalendar();

    // clone object cal into object y
    GregorianCalendar y = (GregorianCalendar) cal.clone();

    // print both cal and y
    System.out.println(cal.getTime());
    System.out.println(y.getTime());

}

From source file:Main.java

public static void main(String[] argv) throws Exception {
    GregorianCalendar gc = new GregorianCalendar();
    gc.setLenient(false);/*from ww w .jav a  2s .co  m*/
    gc.set(GregorianCalendar.YEAR, 2003);
    gc.set(GregorianCalendar.MONTH, 12);
    gc.set(GregorianCalendar.DATE, 1);

    gc.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());
   }// w w w  . ja  v a  2 s .  co  m
}

From source file:Main.java

public static void main(String[] args) {

    GregorianCalendar cal = (GregorianCalendar) GregorianCalendar.getInstance();

    // add 2 months 
    cal.add((GregorianCalendar.MONTH), 2);

    // print the modified date and time
    System.out.println(cal.getTime());

    // add 2 years 
    cal.add((GregorianCalendar.YEAR), 2);

    // print the modified date and time
    System.out.println(cal.getTime());

}

From source file:GregCalDemo.java

public static void main(String[] av) {
    //+/*  w  ww  .  ja  v a2 s .c om*/
    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());
    //-
}