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[] 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); Calendar local = new GregorianCalendar(); local.setTimeInMillis(japanCal.getTimeInMillis()); }
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); Calendar local = new GregorianCalendar(); local.setTimeInMillis(japanCal.getTimeInMillis()); int hour = local.get(Calendar.HOUR); // 5 int minutes = local.get(Calendar.MINUTE); // 0 int seconds = local.get(Calendar.SECOND); // 0 boolean am = local.get(Calendar.AM_PM) == Calendar.AM; // false }
From source file:Main.java
public static void main(String[] args) { Calendar cal = new GregorianCalendar(); System.out.println(cal.getTime()); cal.set(Calendar.AM_PM, Calendar.AM); System.out.println(cal.getTime()); }
From source file:Main.java
public static void main(String[] args) { Calendar cal = new GregorianCalendar(); System.out.println(cal.getTime()); cal.set(Calendar.AM_PM, Calendar.PM); System.out.println(cal.getTime()); }
From source file:Main.java
public static void main(String[] args) { Calendar calendar = Calendar.getInstance(); // 15-04-2012 calendar.set(Calendar.DAY_OF_MONTH, 15); calendar.set(Calendar.YEAR, 2012); calendar.set(Calendar.HOUR, 0); calendar.set(Calendar.MINUTE, 0); calendar.set(Calendar.SECOND, 0); calendar.set(Calendar.MONTH, 3); Date start = calendar.getTime(); // 15-06-2012 calendar.set(Calendar.MONTH, 5); Date end = calendar.getTime(); calendar.setTime(start);/*www .ja v a 2 s . co m*/ Date d = null; while ((d = calendar.getTime()).before(end) || d.equals(end)) { int day = calendar.get(Calendar.DAY_OF_WEEK); if (day != Calendar.SATURDAY && day != Calendar.SUNDAY) { System.out.println(d); } calendar.add(Calendar.DAY_OF_MONTH, 1); } }
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 calendar = Calendar.getInstance(); int lastDate = calendar.getActualMaximum(Calendar.DATE); calendar.set(Calendar.DATE, lastDate); int lastDay = calendar.get(Calendar.DAY_OF_WEEK); System.out.println("Last Date: " + calendar.getTime()); System.out.println("Last Day : " + lastDay); }
From source file:Main.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(); // Set the time and date information and display it. 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)); }
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 w ww .j a v a 2 s .c om*/ }
From source file:com.discursive.jccook.lang.builders.customized.PoliticalCandidate.java
public static void main(String[] args) { // Create a State State va = new State("VA", "Virginia"); // Create a Birth Date Calendar calendar = new GregorianCalendar(); calendar.set(Calendar.YEAR, 1743); calendar.set(Calendar.MONTH, Calendar.APRIL); calendar.set(Calendar.DAY_OF_MONTH, 13); Date dob = calendar.getTime(); BigDecimal moneyRaised = new BigDecimal(293829292.93); // Create a Political Candidate PoliticalCandidate candidate = new PoliticalCandidate("Jefferson", "Thomas", dob, moneyRaised, va); System.out.println(candidate); }