List of usage examples for java.util Calendar YEAR
int YEAR
To view the source code for java.util Calendar YEAR.
Click Source Link
get
and set
indicating the year. From source file:Main.java
public static void main(String[] args) { Calendar cal = Calendar.getInstance(); System.out.println("The current date is : " + cal.getTime()); // add 20 days to the calendar cal.add(Calendar.DATE, 20);/*from w w w . j a v a2s .c o m*/ System.out.println("20 days later: " + cal.getTime()); // subtract 2 months from the calendar cal.add(Calendar.MONTH, -2); System.out.println("2 months ago: " + cal.getTime()); // subtract 5 year from the calendar cal.add(Calendar.YEAR, -5); System.out.println("5 years ago: " + cal.getTime()); }
From source file:GregCalDemo.java
public static void main(String[] av) { //+/*from w w w . j av a 2 s .co m*/ GregorianCalendar d1 = new GregorianCalendar(1986, 04, 05); // May 5 GregorianCalendar d2 = new GregorianCalendar(); // today Calendar d3 = Calendar.getInstance(); // today System.out.println("It was then " + d1.getTime()); System.out.println("It is now " + d2.getTime()); System.out.println("It is now " + d3.getTime()); d3.set(Calendar.YEAR, 1915); d3.set(Calendar.MONTH, Calendar.APRIL); d3.set(Calendar.DAY_OF_MONTH, 12); System.out.println("D3 set to " + d3.getTime()); //- }
From source file:MainClass.java
public static void main(final String args[]) { JFrame frame = new JFrame("JSpinner Dates"); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); Calendar cal = Calendar.getInstance(); Date now = cal.getTime();/*from w ww. j a va 2s . c o m*/ cal.add(Calendar.YEAR, -50); Date startDate = cal.getTime(); cal.add(Calendar.YEAR, 100); Date endDate = cal.getTime(); SpinnerModel model2 = new SpinnerDateModel(now, startDate, endDate, Calendar.YEAR); JSpinner spinner2 = new JSpinner(model2); JLabel label2 = new JLabel("Range"); JPanel panel2 = new JPanel(new BorderLayout()); panel2.add(label2, BorderLayout.WEST); panel2.add(spinner2, BorderLayout.CENTER); frame.add(panel2, BorderLayout.SOUTH); frame.setSize(200, 90); frame.setVisible(true); }
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)); }
From source file:MainClass.java
public static void main(String[] a) { Calendar calendar = new GregorianCalendar(); calendar.setTime(new Date()); System.out.println("ERA: " + calendar.get(Calendar.ERA)); System.out.println("YEAR: " + calendar.get(Calendar.YEAR)); System.out.println("MONTH: " + calendar.get(Calendar.MONTH)); System.out.println("WEEK_OF_YEAR: " + calendar.get(Calendar.WEEK_OF_YEAR)); System.out.println("WEEK_OF_MONTH: " + calendar.get(Calendar.WEEK_OF_MONTH)); System.out.println("DATE: " + calendar.get(Calendar.DATE)); System.out.println("DAY_OF_MONTH: " + calendar.get(Calendar.DAY_OF_MONTH)); System.out.println("DAY_OF_WEEK: " + calendar.get(Calendar.DAY_OF_WEEK)); System.out.println("DAY_OF_WEEK_IN_MONTH: " + calendar.get(Calendar.DAY_OF_WEEK_IN_MONTH)); System.out.println("AM_PM: " + calendar.get(Calendar.AM_PM)); System.out.println("MILLISECOND: " + calendar.get(Calendar.MILLISECOND)); System.out.println("ZONE_OFFSET: " + (calendar.get(Calendar.ZONE_OFFSET) / (60 * 60 * 1000))); System.out.println("DST_OFFSET: " + (calendar.get(Calendar.DST_OFFSET) / (60 * 60 * 1000))); }
From source file:MainClass.java
public static void main(String[] args) throws ParseException { SimpleDateFormat sdf = new SimpleDateFormat("MM/dd/yyyy"); GregorianCalendar gc = new GregorianCalendar(); java.util.Date d = sdf.parse("12/12/2003"); gc.setTime(d);/*w w w . j a va 2s .c om*/ System.out.println("Input Date = " + sdf.format(d)); int dayBefore = gc.get(Calendar.DAY_OF_YEAR); gc.roll(Calendar.DAY_OF_YEAR, -1); int dayAfter = gc.get(Calendar.DAY_OF_YEAR); if (dayAfter > dayBefore) { gc.roll(Calendar.YEAR, -1); } gc.get(Calendar.DATE); java.util.Date yesterday = gc.getTime(); System.out.println("Yesterdays Date = " + sdf.format(yesterday)); }
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 w w . ja v a 2 s .co m*/ new Timer().scheduleAtFixedRate(new test1(), start.getTime(), DateUtils.MILLIS_PER_MINUTE); }
From source file:MainClass.java
public static void main(String[] pArgs) throws Exception { Date now = new Date(); Date truncYear = DateUtils.truncate(now, Calendar.YEAR); Date truncMonth = DateUtils.truncate(now, Calendar.MONTH); System.out.println("now: " + DateFormatUtils.ISO_DATETIME_TIME_ZONE_FORMAT.format(now)); System.out.println("truncYear: " + DateFormatUtils.ISO_DATETIME_TIME_ZONE_FORMAT.format(truncYear)); System.out.println("truncMonth: " + DateFormatUtils.ISO_DATETIME_TIME_ZONE_FORMAT.format(truncMonth)); }
From source file:PriorityQueueTest.java
public static void main(String[] args) { PriorityQueue<GregorianCalendar> pq = new PriorityQueue<GregorianCalendar>(); pq.add(new GregorianCalendar(1906, Calendar.DECEMBER, 9)); // G. Hopper pq.add(new GregorianCalendar(1815, Calendar.DECEMBER, 10)); // A. Lovelace pq.add(new GregorianCalendar(1903, Calendar.DECEMBER, 3)); // J. von Neumann pq.add(new GregorianCalendar(1910, Calendar.JUNE, 22)); // K. Zuse System.out.println("Iterating over elements..."); for (GregorianCalendar date : pq) System.out.println(date.get(Calendar.YEAR)); System.out.println("Removing elements..."); while (!pq.isEmpty()) System.out.println(pq.remove().get(Calendar.YEAR)); }
From source file:com.discursive.jccook.lang.builders.reflect.PoliticalCandidate.java
public static void main(String[] args) { // START lang-ex-sample-1 // 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); // END lang-ex-sample-1 }