List of usage examples for java.util Calendar getTime
public final Date getTime()
Date
object representing this Calendar
's time value (millisecond offset from the Epoch"). From source file:Main.java
public static void main(String args[]) { Calendar cal1 = new GregorianCalendar(); Calendar cal2 = new GregorianCalendar(); cal1.set(2010, 12, 1);//from w w w .j ava 2 s . c o m cal2.set(2011, 9, 31); System.out.println("Days= " + daysBetween(cal1.getTime(), cal2.getTime())); }
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);//w w w . j a va 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[]) { Calendar c1 = new GregorianCalendar(); Calendar c2 = new GregorianCalendar(); c1.set(2000, 12, 12, 0, 0, 0);//from w w w .jav a 2 s. c o m c2.set(2001, 12, 12, 0, 0, 0); System.out.println(daysBetween(c1.getTime(), c2.getTime()) + " day(s) between " + args[0] + "-" + args[1] + "-" + args[2] + " and " + args[3] + "-" + args[4] + "-" + args[5]); }
From source file:GregCalDemo.java
public static void main(String[] av) { //+//ww w. j a v a2s.c o 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:CalCalcs.java
public static void main(String[] argv) { //+/*w w w. j ava 2 s.c o m*/ Calendar c = Calendar.getInstance(); System.out.println("I got a " + c.getClass()); c.set(1951, 03, 24, 12, 30, 0); System.out.println("I set it to " + c.getTime().toString()); System.out.println("I actually set the year to " + c.get(Calendar.YEAR)); System.out.println("In milliseconds, that's " + c.getTime().getTime()); System.out.println("Or, in seconds, " + c.getTime().getTime() / 1000); //- }
From source file:Test.java
public static void main(String[] args) { Locale locale = Locale.getDefault(); Calendar calendar = Calendar.getInstance(); calendar.setWeekDate(2012, 16, 3);/*from ww w . java 2 s. co m*/ System.out.println( DateFormat.getDateTimeInstance(DateFormat.LONG, DateFormat.LONG).format(calendar.getTime())); System.out.println("" + locale.getDisplayLanguage()); Locale.setDefault(Locale.Category.FORMAT, Locale.JAPANESE); Locale.setDefault(Locale.Category.DISPLAY, Locale.GERMAN); System.out.println( DateFormat.getDateTimeInstance(DateFormat.LONG, DateFormat.LONG).format(calendar.getTime())); System.out.println("" + locale.getDisplayLanguage()); }
From source file:Main.java
public static void main(String[] args) { int year = 2009; int month = 0; // January int date = 1; Calendar cal = Calendar.getInstance(); cal.clear();/*from ww w .j a va 2s . c o m*/ cal.set(Calendar.YEAR, year); cal.set(Calendar.MONTH, month); cal.set(Calendar.DATE, date); java.util.Date utilDate = cal.getTime(); System.out.println(utilDate); }
From source file:Main.java
public static void main(String[] args) { Calendar calendar = Calendar.getInstance(); calendar.set(Calendar.YEAR, 2007); calendar.set(Calendar.DAY_OF_YEAR, 180); // See the full information of the calendar object. System.out.println(calendar.getTime().toString()); // Get the weekday and print it int weekday = calendar.get(Calendar.DAY_OF_WEEK); System.out.println("Weekday: " + weekday); }
From source file:DateCalAdd.java
public static void main(String[] av) { /** Today's date */ Calendar now = Calendar.getInstance(); /* Do "DateFormat" using "simple" format. */ SimpleDateFormat formatter = new SimpleDateFormat("E yyyy/MM/dd 'at' hh:mm:ss a zzz"); System.out.println("It is now " + formatter.format(now.getTime())); now.add(Calendar.YEAR, -2);/*from w w w. j a v a2s . c o m*/ System.out.println("Two years ago was " + formatter.format(now.getTime())); }
From source file:Main.java
public static void main(String[] args) { Date today = new Date(); Calendar calendar = Calendar.getInstance(); calendar.setTime(today);/*from w w w . j a v a 2s.com*/ calendar.add(Calendar.MONTH, 1); calendar.set(Calendar.DAY_OF_MONTH, 1); calendar.add(Calendar.DATE, -1); Date lastDayOfMonth = calendar.getTime(); DateFormat sdf = new SimpleDateFormat("yyyy-MM-dd"); System.out.println("Today : " + sdf.format(today)); System.out.println("Last Day of Month: " + sdf.format(lastDayOfMonth)); }