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
/** * Convert string format date data to whooing date format integer * @param dateStr Date data formatted string like "05/21" * @return Return whooing style integer date like 20121212 otherwise -1 * *///from w w w . ja v a 2 s.com static public int convertWhooingDate(String dateStr) { String convertDate = dateStr.replace("/", ""); if (convertDate.length() == 3) { convertDate = "0" + convertDate; } Calendar rightNow = Calendar.getInstance(); int year = rightNow.get(Calendar.YEAR); int month = rightNow.get(Calendar.MONTH) + 1; int day = rightNow.get(Calendar.DAY_OF_MONTH); int today = year * 10000 + month * 100 + day; convertDate = year + convertDate; int convertDateInt = 0; try { convertDateInt = Integer.valueOf(convertDate); // In case of receiving message 12/31 on 1 Jan if ((today / 10000) < (convertDateInt / 10000)) { convertDateInt -= 10000; } } catch (NumberFormatException e) { e.printStackTrace(); } //guard wrong date if (convertDateInt < ((year * 10000) + 101)) { convertDateInt = today; } return convertDateInt; }
From source file:Main.java
public static Date getEndDateOfMonth(int year, int month) throws ParseException { SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd"); Calendar cal = Calendar.getInstance(); cal.set(Calendar.MONTH, month); cal.set(Calendar.YEAR, year); String enddat = year + "-" + (month + 1) + "-" + cal.getActualMaximum(Calendar.DATE); Date enddate = sdf.parse(enddat); return enddate; }
From source file:Main.java
public static Date getStartDateOfMonth(int year, int month) throws ParseException { SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd"); Calendar cal = Calendar.getInstance(); cal.set(Calendar.MONTH, month); cal.set(Calendar.YEAR, year); String startdat = year + "-" + (month + 1) + "-01"; Date startdate = sdf.parse(startdat); return startdate; }
From source file:Main.java
/** Convert a calendar date into a string as specified by http://tools.ietf.org/html/rfc822#section-5.1 * @param date the calendar instance to convert to a string * @param locale the locale to use when outputting strings such as a day of the week, or month of the year. * @return a string in the format: "day_abbreviation, day_of_month month_abbreviation year hour:minute:second GMT" *///ww w . ja va 2 s. co m // package-private - unused static final String convertDateToStringRfc822(Calendar date, Locale locale) { Date a = Date.from(Instant.now()); a.toString(); int day = date.get(Calendar.DAY_OF_MONTH); int hour = date.get(Calendar.HOUR_OF_DAY); int minute = date.get(Calendar.MINUTE); int second = date.get(Calendar.SECOND); String str = date.getDisplayName(Calendar.DAY_OF_WEEK, Calendar.SHORT, locale) + ", " + (day < 10 ? "0" + day : day) + " " + date.getDisplayName(Calendar.MONTH, Calendar.SHORT, locale) + " " + date.get(Calendar.YEAR) + " " + (hour < 10 ? "0" + hour : hour) + ":" + (minute < 10 ? "0" + minute : minute) + ":" + (second < 10 ? "0" + second : second) + " GMT"; return str; }
From source file:Main.java
/** * Formats a birthday date to a String * @param bDay date in <i>"mm/dd/yyyy"</i> format * @return formated date string </br><b>Format : </b> "yyyy-MM-dd HH:mm:ss" */// www . java 2s . c o m public static String formatDate(String bDay) { Calendar calDob = Calendar.getInstance(); String formated = ""; if (bDay != null) { String[] mmddyyyy = bDay.split("/"); if (mmddyyyy.length == 3) { calDob.set(calDob.get(Calendar.YEAR), Integer.parseInt(mmddyyyy[0]) - 1, Integer.parseInt(mmddyyyy[1]), 23, 59, 59); } else if (mmddyyyy.length == 2) { calDob.set(calDob.get(Calendar.YEAR), Integer.parseInt(mmddyyyy[0]) - 1, Integer.parseInt(mmddyyyy[1]), 23, 59, 59); } SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss", Locale.US); dateFormat.setCalendar(calDob); formated = dateFormat.format(calDob.getTime()); } return formated; }
From source file:Main.java
/** * Formats a birthday date to a String * @param bDay date in <i>"yyyy-mm-dd"</i> format * @return formated date string </br><b>Format : </b> "yyyy-MM-dd HH:mm:ss" */// w ww . java 2s . c o m public static String formatContactDate(String bDay) { Calendar calDob = Calendar.getInstance(); String formated = ""; if (bDay != null) { String[] mmddyyyy = bDay.split("-"); if (mmddyyyy.length == 3) { calDob.set(calDob.get(Calendar.YEAR), Integer.parseInt(mmddyyyy[1]) - 1, Integer.parseInt(mmddyyyy[2]), 23, 59, 59); } else if (mmddyyyy.length == 2) { calDob.set(calDob.get(Calendar.YEAR), Integer.parseInt(mmddyyyy[1]) - 1, Integer.parseInt(mmddyyyy[2]), 23, 59, 59); } SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss", Locale.US); dateFormat.setCalendar(calDob); formated = dateFormat.format(calDob.getTime()); } return formated; }
From source file:Main.java
protected static String toString(GregorianCalendar g1) { StringBuilder buffer = new StringBuilder(); buffer.append(/* ww w . ja v a2 s .c o m*/ g1.get(Calendar.YEAR) + "/" + (g1.get(Calendar.MONTH) + 1) + "/" + g1.get(Calendar.DAY_OF_MONTH)); buffer.append(" "); buffer.append(g1.get(Calendar.HOUR_OF_DAY) + ":" + g1.get(Calendar.MINUTE) + ":" + g1.get(Calendar.SECOND) + "." + g1.get(Calendar.MILLISECOND)); return buffer.toString(); }
From source file:de.dominikschadow.duke.encounters.repositories.EncounterSpecification.java
public static Specification<Encounter> encounterAfterYear(int year) { Calendar calendar = Calendar.getInstance(); calendar.set(Calendar.YEAR, year); return (root, query, cb) -> cb.greaterThanOrEqualTo(root.<Date>get("date"), calendar.getTime()); }
From source file:Main.java
@NonNull static Date convertDate(int date, int time) { Calendar calendar = Calendar.getInstance(); calendar.set(Calendar.YEAR, 1997); calendar.set(Calendar.MONTH, Calendar.JANUARY); calendar.set(Calendar.DAY_OF_MONTH, 1); calendar.set(Calendar.HOUR_OF_DAY, time / 60); calendar.set(Calendar.MINUTE, time % 60); calendar.add(Calendar.DATE, date); return calendar.getTime(); }
From source file:Main.java
public static boolean isInPast(int day, int month, int year) { Calendar c = Calendar.getInstance(); c.set(Calendar.YEAR, year); c.set(Calendar.MONTH, month - 1); c.set(Calendar.DAY_OF_MONTH, day); Date pastDate = c.getTime();/* w w w . j a v a2s. c o m*/ return (pastDate.getTime() < new Date().getTime()); }