List of usage examples for java.util Calendar DATE
int DATE
To view the source code for java.util Calendar DATE.
Click Source Link
get
and set
indicating the day of the month. 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();// w w w. j a va 2s . c o m cal.set(Calendar.YEAR, year); cal.set(Calendar.MONTH, month); cal.set(Calendar.DATE, date); java.sql.Date sqlDate = new java.sql.Date(cal.getTimeInMillis()); System.out.println(sqlDate); }
From source file:Main.java
public static void main(String[] args) { GregorianCalendar gc = new GregorianCalendar(); System.out.println("Current Date: " + gc.getTime()); // Add 1 year gc.add(Calendar.YEAR, 1);// w w w. j a va 2 s . c o m System.out.println(gc.getTime()); // Add 15 days gc.add(Calendar.DATE, 15); System.out.println(gc.getTime()); }
From source file:Main.java
public static void main(String[] args) { Calendar now = Calendar.getInstance(); // /*from w w w . j a v a 2s . c o m*/ System.out.println("Current Year is : " + now.get(Calendar.YEAR)); // month start from 0 to 11 System.out.println("Current Month is : " + (now.get(Calendar.MONTH) + 1)); System.out.println("Current Date is : " + now.get(Calendar.DATE)); }
From source file:MainClass.java
public static void main(String[] args) { // get a calendar using the default time zone and locale. Calendar calendar = Calendar.getInstance(); // set Date portion to January 1, 1970 calendar.set(Calendar.YEAR, 1970); calendar.set(Calendar.MONTH, Calendar.JANUARY); calendar.set(Calendar.DATE, 1); // normalize the object calendar.set(Calendar.HOUR_OF_DAY, 0); calendar.set(Calendar.MINUTE, 0); calendar.set(Calendar.SECOND, 0); calendar.set(Calendar.MILLISECOND, 0); java.sql.Date javaSqlDate = new java.sql.Date(calendar.getTime().getTime()); }
From source file:Main.java
public static void main(String[] args) { Calendar cal = Calendar.getInstance(); // get the value of all the calendar date fields. System.out.println("Calendar's Year: " + cal.get(Calendar.YEAR)); System.out.println("Calendar's Month: " + cal.get(Calendar.MONTH)); System.out.println("Calendar's Day: " + cal.get(Calendar.DATE)); }
From source file:Main.java
public static void main(String[] args) { Date today = new Date(); Calendar calendar = Calendar.getInstance(); calendar.setTime(today);/*w w w .j a v a2s. 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)); }
From source file:Main.java
public static void main(String[] args) { DateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:00Z"); Calendar cal = Calendar.getInstance(); cal.set(Calendar.YEAR, 2015); cal.set(Calendar.MONTH, Calendar.SEPTEMBER); cal.set(Calendar.DATE, 1); cal.set(Calendar.HOUR_OF_DAY, 12); cal.set(Calendar.MINUTE, 15); Date date = cal.getTime();//w w w. j a v a2s . co m System.out.println(date); TimeZone tz = TimeZone.getTimeZone("IST"); dateFormat.setTimeZone(tz); String actual = dateFormat.format(date); System.out.println(actual); }
From source file:Main.java
public static void main(String[] args) { Calendar now = Calendar.getInstance(); 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.add(Calendar.WEEK_OF_MONTH, 1); System.out.println("date after one year : " + (now.get(Calendar.MONTH) + 1) + "-" + now.get(Calendar.DATE) + "-" + now.get(Calendar.YEAR)); }
From source file:GregorianCalendarDemo.java
public static void main(String args[]) { String months[] = { "Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec" }; int year;/* w w w . j av a 2 s. co m*/ GregorianCalendar gcalendar = new GregorianCalendar(); System.out.print("Date: "); System.out.print(months[gcalendar.get(Calendar.MONTH)]); System.out.print(" " + gcalendar.get(Calendar.DATE) + " "); System.out.println(year = gcalendar.get(Calendar.YEAR)); System.out.print("Time: "); System.out.print(gcalendar.get(Calendar.HOUR) + ":"); System.out.print(gcalendar.get(Calendar.MINUTE) + ":"); System.out.println(gcalendar.get(Calendar.SECOND)); if (gcalendar.isLeapYear(year)) { System.out.println("The current year is a leap year"); } else { System.out.println("The current year is not a leap year"); } }
From source file:MainClass.java
public static void main(String args[]) { String months[] = { "Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec" }; Calendar calendar = Calendar.getInstance(); System.out.print("Date: "); System.out.print(months[calendar.get(Calendar.MONTH)]); System.out.print(" " + calendar.get(Calendar.DATE) + " "); System.out.println(calendar.get(Calendar.YEAR)); System.out.print("Time: "); System.out.print(calendar.get(Calendar.HOUR) + ":"); System.out.print(calendar.get(Calendar.MINUTE) + ":"); System.out.println(calendar.get(Calendar.SECOND)); calendar.set(Calendar.HOUR, 10); calendar.set(Calendar.MINUTE, 29); calendar.set(Calendar.SECOND, 22); System.out.print("Updated time: "); System.out.print(calendar.get(Calendar.HOUR) + ":"); System.out.print(calendar.get(Calendar.MINUTE) + ":"); System.out.println(calendar.get(Calendar.SECOND)); }