List of usage examples for java.util Calendar get
public int get(int field)
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:Main.java
public static void main(String[] args) { Calendar now = Calendar.getInstance(); System.out.println(now.getTime()); System.out.println(now.get(Calendar.WEEK_OF_YEAR)); }
From source file:Main.java
public static void main(String[] args) { Calendar now = Calendar.getInstance(); System.out.println(now.getTime()); System.out.println(now.get(Calendar.HOUR_OF_DAY)); }
From source file:Main.java
public static void main(String[] args) { Calendar now = Calendar.getInstance(); System.out.println(now.getTime()); System.out.println(now.get(Calendar.WEEK_OF_MONTH)); }
From source file:Main.java
public static void main(String[] args) { Calendar now = Calendar.getInstance(); System.out.println("Current Hour in 12 hour format is : " + now.get(Calendar.HOUR)); System.out.println("Current Hour in 24 hour format is : " + now.get(Calendar.HOUR_OF_DAY)); System.out.println("Current Minute is : " + now.get(Calendar.MINUTE)); System.out.println("Current Second is : " + now.get(Calendar.SECOND)); System.out.println("Current Millisecond is : " + now.get(Calendar.MILLISECOND)); }
From source file:Main.java
public static void main(String[] argv) throws Exception { Calendar cal = new GregorianCalendar(); // Get the components of the time int hour12 = cal.get(Calendar.HOUR); // 0..11 int hour24 = cal.get(Calendar.HOUR_OF_DAY); // 0..23 int min = cal.get(Calendar.MINUTE); // 0..59 int sec = cal.get(Calendar.SECOND); // 0..59 int ms = cal.get(Calendar.MILLISECOND); // 0..999 int ampm = cal.get(Calendar.AM_PM); // 0=AM, 1=PM }
From source file:Main.java
public static void main(String[] argv) throws Exception { // Get the current time in Hong Kong Calendar cal = new GregorianCalendar(TimeZone.getTimeZone("Hongkong")); int hour12 = cal.get(Calendar.HOUR); // 0..11 int minutes = cal.get(Calendar.MINUTE); // 0..59 int seconds = cal.get(Calendar.SECOND); // 0..59 boolean am = cal.get(Calendar.AM_PM) == Calendar.AM; // Get the current hour-of-day at GMT cal.setTimeZone(TimeZone.getTimeZone("GMT")); int hour24 = cal.get(Calendar.HOUR_OF_DAY); // 0..23 // Get the current local hour-of-day cal.setTimeZone(TimeZone.getDefault()); hour24 = cal.get(Calendar.HOUR_OF_DAY); // 0..23 }
From source file:DatePrint1.java
public static void main(String[] argv) { //+/*w w w.j a v a2 s . c om*/ Calendar c = new GregorianCalendar(1918, 10, 11); System.out.println(c.get(Calendar.DAY_OF_MONTH) + " " + c.get(Calendar.MONTH) + ", " + c.get(Calendar.YEAR) + " " + c.get(Calendar.ERA)); //- }
From source file:com.pureinfo.srm.config.notice.TestTimer.java
public static void main(String[] args) throws ParseException { Calendar start = new GregorianCalendar(); start.setTime(format.parse("18:40")); Calendar cal = new GregorianCalendar(); start.set(Calendar.YEAR, cal.get(Calendar.YEAR)); start.set(Calendar.MONTH, cal.get(Calendar.MONTH)); start.set(Calendar.DAY_OF_MONTH, cal.get(Calendar.DAY_OF_MONTH)); while (start.before(cal)) { start.setTimeInMillis(start.getTimeInMillis() + DateUtils.MILLIS_PER_MINUTE); }//from w ww. j a v a 2 s .com new Timer().scheduleAtFixedRate(new test1(), start.getTime(), DateUtils.MILLIS_PER_MINUTE); }
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)); }