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
/** * Sets the years field to a date returning a new object. * The original date object is unchanged. * * @param date the date, not null//from www . ja va2s . co m * @param amount the amount to set * @return a new Date object set with the specified value * @throws IllegalArgumentException if the date is null * @since 2.4 */ public static Date setYears(Date date, int amount) { return set(date, Calendar.YEAR, amount); }
From source file:view.PnIncome.java
/** * Creates new form PnHotel/*from w ww.jav a 2 s. c om*/ */ public PnIncome() { this.mQuarter = Constant.MONTH_OF_QUARTER; initComponents(); pnFind.add(new PnIncomeFindMonth(), BorderLayout.CENTER); Calendar now = Calendar.getInstance(); drawDateChartMonth(now.get(Calendar.MONTH) + 1, now.get(Calendar.YEAR)); mPnIncomeFindMonth = new PnIncomeFindMonth(); mPnIncomeFindMonth.getCbMonth().addActionListener((ActionEvent e) -> { pnCenter.removeAll(); drawDateChartMonth((int) mPnIncomeFindMonth.getCbMonth().getSelectedItem(), (int) mPnIncomeFindMonth.getCbYear().getSelectedItem()); }); mPnIncomeFindMonth.getCbYear().addActionListener((ActionEvent e) -> { pnCenter.removeAll(); drawDateChartMonth((int) mPnIncomeFindMonth.getCbMonth().getSelectedItem(), (int) mPnIncomeFindMonth.getCbYear().getSelectedItem()); }); mPnIncomeFindQuarter = new PnIncomeFindQuarter(); mPnIncomeFindQuarter.getCbQuarter().addActionListener((ActionEvent e) -> { pnCenter.removeAll(); drawDateChartQuarter(Integer.parseInt((String) mPnIncomeFindQuarter.getCbQuarter().getSelectedItem()), (int) mPnIncomeFindQuarter.getCbYear().getSelectedItem()); }); mPnIncomeFindQuarter.getCbYear().addActionListener((ActionEvent e) -> { pnCenter.removeAll(); drawDateChartQuarter((int) mPnIncomeFindQuarter.getCbQuarter().getSelectedItem(), (int) mPnIncomeFindQuarter.getCbYear().getSelectedItem()); }); mPnIncomeFindYear = new PnIncomeFindYear(); mPnIncomeFindYear.getCbYear().addActionListener((ActionEvent e) -> { pnCenter.removeAll(); drawDateChartYear((int) mPnIncomeFindYear.getCbYear().getSelectedItem()); }); }
From source file:com.xumpy.thuisadmin.controllers.model.finances.overviewMonthCategory.OverviewMonthCategoryInput.java
public OverviewMonthCategoryInput() { SimpleDateFormat dt = new SimpleDateFormat("MM/yyyy"); Date dateToday = new Date(); Calendar cal = Calendar.getInstance(); cal.setTime(dateToday);/*from w ww . j ava 2s . c o m*/ cal.add(Calendar.YEAR, -1); Date prevMonth = cal.getTime(); this.beginDate = dt.format(prevMonth); this.endDate = dt.format(dateToday); this.mainGroupValues = new ArrayList<MainGroupValue>(); }
From source file:Main.java
public static String formatExpirationDate(String text) { try {//from ww w . j a v a 2 s . c om switch (text.length()) { case 1: int digit = Integer.parseInt(text); if (digit < 2) { return text; } else { return "0" + text + "/"; } case 2: int month = Integer.parseInt(text); if (month > 12 || month < 1) { // Invalid digit return text.substring(0, 1); } else { return text + "/"; } case 3: if (text.substring(2, 3).equalsIgnoreCase("/")) { return text; } else { text = text.substring(0, 2) + "/" + text.substring(2, 3); } case 4: Calendar now = getCurrentExpDate(); String year = String.valueOf(now.get(Calendar.YEAR)); int yearDigit = Integer.parseInt(text.substring(3, 4)); int currentYearDigit = Integer.parseInt(year.substring(2, 3)); if (yearDigit < currentYearDigit) { // Less than current year invalid return text.substring(0, 3); } else { return text; } case 5: Calendar now2 = getCurrentExpDate(); String currentYearStr2 = String.valueOf(now2.get(Calendar.YEAR)); String yearStr = text.substring(0, 3) + currentYearStr2.substring(0, 2) + text.substring(3, 5); Date expiry = simpleDateFormat.parse(yearStr); if (expiry.before(now2.getTime())) { // Invalid exp date return text.substring(0, 4); } else { return text; } default: if (text.length() > 5) { return text.substring(0, 5); } else { return text; } } } catch (ParseException e) { e.printStackTrace(); } // If an exception is thrown we clear out the text return ""; }
From source file:com.autentia.tnt.bean.reports.BillReportBean.java
@Override public ArrayList<SelectItem> getYears() { final ArrayList<SelectItem> reto = new ArrayList<SelectItem>(); int year = Calendar.getInstance().get(Calendar.YEAR); for (int i = year; i >= 2006; i--) { String b = Integer.toString(i); reto.add(new SelectItem(b, b)); }// ww w. j a va2s . c om return reto; }
From source file:net.netheos.pcsapi.providers.hubic.SwiftTest.java
@Test public void testParseTimestamp() { // Check we won't break if a header is missing : Headers headers = new Headers(); Date timestamp = Swift.parseTimestamp(headers); assertNull(timestamp);/* w w w . j av a2 s. com*/ headers.addHeader("X-Timestamp", "1383925113.43900"); // 2013-11-08T16:38:33.439+01:00 timestamp = Swift.parseTimestamp(headers); Calendar cal = Calendar.getInstance(TimeZone.getTimeZone("GMT")); cal.setTime(timestamp); System.out.println(timestamp); assertEquals(2013, cal.get(Calendar.YEAR)); assertEquals(Calendar.NOVEMBER, cal.get(Calendar.MONTH)); assertEquals(8, cal.get(Calendar.DAY_OF_MONTH)); assertEquals(15, cal.get(Calendar.HOUR_OF_DAY)); assertEquals(38, cal.get(Calendar.MINUTE)); assertEquals(33, cal.get(Calendar.SECOND)); assertEquals(439, cal.get(Calendar.MILLISECOND)); checkTimestamp("1383925113.430723", new Date(1383925113430L)); checkTimestamp("1383925113.43900", new Date(1383925113439L)); checkTimestamp("1383925113.439", new Date(1383925113439L)); checkTimestamp("1383925113.43", new Date(1383925113430L)); checkTimestamp("1383925113.4", new Date(1383925113400L)); checkTimestamp("1383925113.", new Date(1383925113000L)); checkTimestamp("1383925113", new Date(1383925113000L)); }
From source file:DateUtils.java
public static String getTimestamp() { Calendar cal = Calendar.getInstance(); cal.setTime(new Date()); int year = cal.get(Calendar.YEAR); int month = cal.get(Calendar.MONTH) + 1; int day = cal.get(Calendar.DAY_OF_MONTH); int hours = cal.get(Calendar.HOUR_OF_DAY); // use 24 hour clock int minutes = cal.get(Calendar.MINUTE); int seconds = cal.get(Calendar.SECOND); int milli = cal.get(Calendar.MILLISECOND); return "" + year + "-" + month + "-" + day + "_" + formatTime(hours, minutes, seconds, milli); }
From source file:com.mb.framework.util.DateTimeUtil.java
/** * This method is used for getting the number corresponding to Calendar year * /*from www. j a v a2 s.c o m*/ * @param year * @return */ public static int getYear(Date year) { Calendar calendar = Calendar.getInstance(); calendar.setTime(year); return calendar.get(Calendar.YEAR); }
From source file:JapaneseCalendar.java
public void paintComponent(Graphics g) { int width = 400; int height = 400; Calendar cal = Calendar.getInstance(locale); cal.setTime(new Date()); String header = cal.getDisplayName(Calendar.MONTH, Calendar.LONG, locale); header += " " + cal.get(Calendar.YEAR); FontMetrics fm = g.getFontMetrics(); Insets insets = getInsets();/*from w w w . j av a2s .c o m*/ g.setColor(Color.black); g.drawString(header, (width - fm.stringWidth(header)) / 2, insets.top + fm.getHeight()); DateFormatSymbols dfs = new DateFormatSymbols(locale); String[] weekdayNames = dfs.getShortWeekdays(); int fieldWidth = (width - insets.left - insets.right) / 7; g.drawString(weekdayNames[Calendar.SUNDAY], insets.left + (fieldWidth - fm.stringWidth(weekdayNames[Calendar.SUNDAY])) / 2, insets.top + 3 * fm.getHeight()); g.drawString(weekdayNames[Calendar.MONDAY], insets.left + fieldWidth + (fieldWidth - fm.stringWidth(weekdayNames[Calendar.MONDAY])) / 2, insets.top + 3 * fm.getHeight()); g.drawString(weekdayNames[Calendar.TUESDAY], insets.left + 2 * fieldWidth + (fieldWidth - fm.stringWidth(weekdayNames[Calendar.TUESDAY])) / 2, insets.top + 3 * fm.getHeight()); g.drawString(weekdayNames[Calendar.WEDNESDAY], insets.left + 3 * fieldWidth + (fieldWidth - fm.stringWidth(weekdayNames[Calendar.WEDNESDAY])) / 2, insets.top + 3 * fm.getHeight()); g.drawString(weekdayNames[Calendar.THURSDAY], insets.left + 4 * fieldWidth + (fieldWidth - fm.stringWidth(weekdayNames[Calendar.THURSDAY])) / 2, insets.top + 3 * fm.getHeight()); g.drawString(weekdayNames[Calendar.FRIDAY], insets.left + 5 * fieldWidth + (fieldWidth - fm.stringWidth(weekdayNames[Calendar.FRIDAY])) / 2, insets.top + 3 * fm.getHeight()); g.drawString(weekdayNames[Calendar.SATURDAY], insets.left + 6 * fieldWidth + (fieldWidth - fm.stringWidth(weekdayNames[Calendar.SATURDAY])) / 2, insets.top + 3 * fm.getHeight()); int dom = cal.get(Calendar.DAY_OF_MONTH); cal.set(Calendar.DAY_OF_MONTH, 1); int col = 0; switch (cal.get(Calendar.DAY_OF_WEEK)) { case Calendar.MONDAY: col = 1; break; case Calendar.TUESDAY: col = 2; break; case Calendar.WEDNESDAY: col = 3; break; case Calendar.THURSDAY: col = 4; break; case Calendar.FRIDAY: col = 5; break; case Calendar.SATURDAY: col = 6; } cal.set(Calendar.DAY_OF_MONTH, dom); int row = 5 * fm.getHeight(); for (int i = 1; i <= cal.getActualMaximum(Calendar.DAY_OF_MONTH); i++) { g.drawString("" + i, insets.left + fieldWidth * col + (fieldWidth - fm.stringWidth("" + i)) / 2, row); if (++col > 6) { col = 0; row += fm.getHeight(); } } }
From source file:DateTimeUtil.java
/** Convert given date to string<br> * OutputFormat: yyyymmdd_hhmm/*from w w w .j a v a 2s . co m*/ * @return The Date/Time in the format: yyyymmdd_hhmm */ public static String convertToDateStamp(Calendar cal) { String year = String.valueOf(cal.get(Calendar.YEAR)); String month = String.valueOf(cal.get(Calendar.MONTH) + 1); if (month.length() == 1) { month = "0" + month; } String day = String.valueOf(cal.get(Calendar.DAY_OF_MONTH)); if (day.length() == 1) { day = "0" + day; } String hour = String.valueOf(cal.get(Calendar.HOUR_OF_DAY)); if (hour.length() == 1) { hour = "0" + hour; } String minute = String.valueOf(cal.get(Calendar.MINUTE)); if (minute.length() == 1) { minute = "0" + minute; } String second = String.valueOf(cal.get(Calendar.SECOND)); if (second.length() == 1) { second = "0" + second; } String dateStamp = year + month + day + "_" + hour + minute + second; return dateStamp; }