List of usage examples for java.util Calendar getInstance
public static Calendar getInstance()
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())); cal.add(Calendar.DATE, 8);//from www .j a v a2s.c o m System.out.println(df.format(cal.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())); cal.add(Calendar.HOUR, -4);// w ww .j a va2 s. c om System.out.println(df.format(cal.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())); cal.add(Calendar.AM_PM, 1);//from www. j av a 2 s . c o m System.out.println(df.format(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();/*from w ww . j ava 2 s . com*/ // print the result System.out.println("The calendar shows : " + cal.getTime()); }
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[] 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) { Date myDate;/*from www . ja v a 2 s . co m*/ Calendar cal = Calendar.getInstance(); cal.set(Calendar.MONTH, 9); cal.set(Calendar.DATE, 24); cal.set(Calendar.YEAR, 2013); cal.set(Calendar.HOUR, 13); cal.set(Calendar.MINUTE, 45); cal.set(Calendar.SECOND, 52); myDate = cal.getTime(); System.out.println(myDate); }
From source file:Main.java
public static void main(String[] args) { // Calendar to Instant Instant time = Calendar.getInstance().toInstant(); System.out.println(time);// w w w . ja v a2 s .com }
From source file:KVMCalendar.java
public static void main(String[] args) { Calendar cal = Calendar.getInstance(); Date date = new Date(); cal.setTime(date);/*from w w w. j a v a2s . co m*/ int month = cal.get(Calendar.MONTH); int day = cal.get(Calendar.DAY_OF_MONTH); System.out.println("Day is " + day + ", month is " + month); final long MILLIS_PER_DAY = 24 * 60 * 60 * 1000L; long offset = date.getTime(); offset += 20 * MILLIS_PER_DAY; date.setTime(offset); cal.setTime(date); month = cal.get(Calendar.MONTH); day = cal.get(Calendar.DAY_OF_MONTH); System.out.println("In 20 days time, day will " + day + ", month will be " + month); System.out.println(cal); }
From source file:DisplayNames.java
public static void main(String args[]) { Calendar now = Calendar.getInstance(); // Locale locale = Locale.getDefault(); Locale locale = Locale.ITALIAN; Map<String, Integer> names = now.getDisplayNames(Calendar.DAY_OF_WEEK, Calendar.LONG, locale); System.out.println(names);// w ww .ja v a 2 s . com String name = now.getDisplayName(Calendar.DAY_OF_WEEK, Calendar.LONG, locale); System.out.printf("Today is a %s.%n", name); }