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 cal = Calendar.getInstance(); Calendar past = Calendar.getInstance(); System.out.println("Current date: " + cal.getTime()); // change year in past calendar past.set(Calendar.YEAR, 2013); System.out.println("Year is " + past.get(Calendar.YEAR)); // check if calendar date is before current date System.out.println(cal.before(past)); }
From source file:Main.java
public static void main(String[] args) { DateFormat formatter = new SimpleDateFormat("dd/MM/yyyy hh:mm:ss.SSS"); long now = System.currentTimeMillis(); Calendar calendar = Calendar.getInstance(); calendar.setTimeInMillis(now);//from w w w.ja v a 2 s . c om System.out.println(now + " = " + formatter.format(calendar.getTime())); }
From source file:Main.java
public static void main(String[] args) { Calendar cal = Calendar.getInstance(Locale.CANADA); // print the date for canada System.out.println("Date And Time in Canada Is: " + cal.getTime()); }
From source file:Main.java
public static void main(String[] args) { // create calendar object Calendar cal = Calendar.getInstance(); // displays the current date and time System.out.println("Current Calendar Date: " + cal.getTime()); // use clear method to set all field values and time value as undefined. cal.clear();/* w w w . j ava 2 s . c o m*/ // print the result System.out.println("The calendar shows : " + cal.getTime()); }
From source file:Main.java
public static void main(String[] args) { Calendar cal = Calendar.getInstance(); Calendar future = Calendar.getInstance(); System.out.println("Current date: " + cal.getTime()); future.set(Calendar.YEAR, 2015); System.out.println("Year is " + future.get(Calendar.YEAR)); Date time = future.getTime(); if (future.after(cal)) { System.out.println("Date " + time + " is after current date."); }//from ww w . ja v a 2 s .co m }
From source file:Main.java
public static void main(String[] args) { Calendar calendar = Calendar.getInstance(); int lastDate = calendar.getActualMaximum(Calendar.DATE); System.out.println("Date : " + calendar.getTime()); System.out.println("Last Date: " + lastDate); }
From source file:Main.java
public static void main(String[] args) { // create a calendar Calendar cal = Calendar.getInstance(); // gets a calendar using the default time zone and locale. System.out.print("Date And Time Is: " + cal.getTime()); }
From source file:Main.java
public static void main(String[] args) { Calendar cal = Calendar.getInstance(); // display the current date and time System.out.println("Current Calendar Date: " + cal.getTime()); // use clear method to set year as undefined. cal.clear(Calendar.YEAR);// w ww . ja va 2 s . c o m // print the result System.out.println("The calendar shows : " + cal.getTime()); // use clear method to set month as undefined. cal.clear(Calendar.MONTH); System.out.println("The calendar shows : " + cal.getTime()); }
From source file:Main.java
public static void main(String[] args) { int dayOfYear = 112; Calendar calendar = Calendar.getInstance(); calendar.set(Calendar.DAY_OF_YEAR, dayOfYear); System.out.println("Day of year " + dayOfYear + " = " + calendar.getTime()); }
From source file:CalendarManipulation.java
public static void main(String s[]) { Calendar cal = Calendar.getInstance(); DateFormat df = DateFormat.getDateTimeInstance(DateFormat.FULL, DateFormat.MEDIUM); System.out.println(df.format(cal.getTime())); }