List of usage examples for java.util Calendar set
public void set(int field, int value)
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: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: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);/*from w ww .j a va2 s. co m*/ cal.set(Calendar.HOUR_OF_DAY, 12); cal.set(Calendar.MINUTE, 15); Date date = cal.getTime(); 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 calendar = GregorianCalendar.getInstance(); calendar.set(YEAR, 2015); calendar.set(MONTH, MARCH);//from w w w . ja va 2 s .c om calendar.set(DAY_OF_MONTH, 1); System.out.println(calendar.getTime()); calendar.add(DAY_OF_MONTH, -1); System.out.println(calendar.getTime()); }
From source file:Main.java
public static void main(String[] argv) throws Exception { Calendar calendar = new GregorianCalendar(); calendar.set(Calendar.HOUR_OF_DAY, 13); // 1pm SpinnerDateModel dateModel = new SpinnerDateModel(calendar.getTime(), null, null, Calendar.HOUR_OF_DAY); JSpinner spinner = new JSpinner(dateModel); JFormattedTextField tf = ((JSpinner.DefaultEditor) spinner.getEditor()).getTextField(); DefaultFormatterFactory factory = (DefaultFormatterFactory) tf.getFormatterFactory(); DateFormatter formatter = (DateFormatter) factory.getDefaultFormatter(); // Change the date format to only show the hours formatter.setFormat(new SimpleDateFormat("hh:00 a")); //formatter.setFormat(new SimpleDateFormat("HH:00 a")); }
From source file:Main.java
public static void main(String[] args) { Calendar localTime = Calendar.getInstance(); localTime.set(Calendar.HOUR, 17); localTime.set(Calendar.MINUTE, 15); localTime.set(Calendar.SECOND, 20); int hour = localTime.get(Calendar.HOUR); int minute = localTime.get(Calendar.MINUTE); int second = localTime.get(Calendar.SECOND); System.out.printf("Local time : %02d:%02d:%02d\n", hour, minute, second); Calendar germanyTime = new GregorianCalendar(TimeZone.getTimeZone("Germany")); germanyTime.setTimeInMillis(localTime.getTimeInMillis()); hour = germanyTime.get(Calendar.HOUR); minute = germanyTime.get(Calendar.MINUTE); second = germanyTime.get(Calendar.SECOND); System.out.printf("Germany time: %02d:%02d:%02d\n", hour, minute, second); }
From source file:Main.java
public static void main(String[] args) { Calendar someTime = Calendar.getInstance(); someTime.set(Calendar.HOUR_OF_DAY, 17); someTime.set(Calendar.MINUTE, 0); someTime.set(Calendar.SECOND, 0); // convert it to java epoch date Date someDate = toEpochDate(someTime); // create a date object from java.sql.Time Date fromSqlTime = new Date(Time.valueOf("17:00:00").getTime()); // now do the comparison System.out.println("Some Date: " + someDate.toString()); System.out.println("Sql Time: " + fromSqlTime.toString()); System.out.println("Are they equal? " + someDate.equals(fromSqlTime)); }
From source file:Main.java
public static void main(String[] argv) throws Exception { Calendar japanCal = new GregorianCalendar(TimeZone.getTimeZone("Japan")); japanCal.set(Calendar.HOUR_OF_DAY, 10); // 0..23 japanCal.set(Calendar.MINUTE, 0); japanCal.set(Calendar.SECOND, 0); }
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 www . j av a2s. 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) { int year = 2009; int month = 0; // January int date = 1; Calendar cal = Calendar.getInstance(); cal.clear();/*w w w.j a va 2s. c om*/ 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); }