List of usage examples for java.util Calendar getInstance
public static Calendar getInstance()
From source file:Main.java
public static void main(String[] args) { Calendar cal = Calendar.getInstance(); // print current year System.out.println("Current year is :" + cal.get(Calendar.YEAR)); // set the year to something else cal.set(Calendar.YEAR, 2013); // print the result System.out.println("Altered year is :" + cal.get(Calendar.YEAR)); }
From source file:Main.java
public static void main(String[] args) { Calendar cal = Calendar.getInstance(); // get the time in milliseconds System.out.println("Current time is :" + cal.getTime()); // set time to 5000000000 ms after january 1 1970 cal.setTimeInMillis(5000000000L);// ww w . ja va 2s. co m // print the new time System.out.println("After setting Time: " + cal.getTime()); }
From source file:Main.java
public static void main(String[] args) { Calendar cal = Calendar.getInstance(); // get what is the minimal days required in the first week int min = cal.getMinimalDaysInFirstWeek(); System.out.println("Minimal Days in Week: " + min); // set the minimal days required in the first week cal.setMinimalDaysInFirstWeek(2);//from www . j a v a 2 s . c o m // print the result min = cal.getMinimalDaysInFirstWeek(); System.out.println("Minimal Days in Week: " + min); }
From source file:Main.java
public static void main(String[] args) { Calendar now = Calendar.getInstance(); System.out.println("Current date : " + (now.get(Calendar.MONTH) + 1) + "-" + now.get(Calendar.DATE) + "-" + now.get(Calendar.YEAR)); System.out.println("Current week of month is : " + now.get(Calendar.WEEK_OF_MONTH)); System.out.println("Current week of year is : " + now.get(Calendar.WEEK_OF_YEAR)); now = Calendar.getInstance(); now.add(Calendar.WEEK_OF_YEAR, -50); System.out.println("date before 50 weeks : " + (now.get(Calendar.MONTH) + 1) + "-" + now.get(Calendar.DATE) + "-" + now.get(Calendar.YEAR)); }
From source file:Main.java
public static void main(String[] args) { Calendar cal = Calendar.getInstance(); cal.set(Calendar.YEAR, 2007); cal.set(Calendar.DAY_OF_YEAR, 180); System.out.println("Calendar date is: " + cal.getTime()); int dayOfMonth = cal.get(Calendar.DAY_OF_MONTH); System.out.println("Calendar day of month: " + dayOfMonth); int dayOfWeek = cal.get(Calendar.DAY_OF_WEEK); System.out.println("Calendar day of week: " + dayOfWeek); }
From source file:MainClass.java
public static void main(String args[]) { Calendar dateTime = Calendar.getInstance(); System.out.printf("%tc\n", dateTime); System.out.printf("%tF\n", dateTime); System.out.printf("%tD\n", dateTime); System.out.printf("%tr\n", dateTime); System.out.printf("%tT\n", dateTime); }
From source file:Main.java
public static void main(String[] args) { Calendar cal = Calendar.getInstance(); boolean b = cal.isSet(Calendar.DAY_OF_MONTH); System.out.println("Day of month is set: " + b); // clear day of month cal.clear(Calendar.DAY_OF_MONTH); // determine if the given calendar field has a value set b = cal.isSet(Calendar.DAY_OF_MONTH); System.out.println("Day of month is set: " + b); }
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) { Calendar cal = Calendar.getInstance(); int day = cal.get(Calendar.DATE); int month = cal.get(Calendar.MONTH) + 1; int year = cal.get(Calendar.YEAR); int dow = cal.get(Calendar.DAY_OF_WEEK); int dom = cal.get(Calendar.DAY_OF_MONTH); int doy = cal.get(Calendar.DAY_OF_YEAR); System.out.println("Current Date: " + cal.getTime()); System.out.println("Day: " + day); System.out.println("Month: " + month); System.out.println("Year: " + year); System.out.println("Day of Week: " + dow); System.out.println("Day of Month: " + dom); System.out.println("Day of Year: " + doy); }
From source file:MainClass.java
public static void main(String[] args) { Calendar calendar = Calendar.getInstance(); System.out.println(calendar.get(Calendar.YEAR)); System.out.println(calendar.get(Calendar.MONTH)); System.out.println(calendar.get(Calendar.DATE)); System.out.println(calendar.get(Calendar.HOUR)); System.out.println(calendar.get(Calendar.MINUTE)); System.out.println(calendar.get(Calendar.SECOND)); System.out.println(calendar.get(Calendar.MILLISECOND)); }