List of usage examples for java.util Calendar getDisplayName
public String getDisplayName(int field, int style, Locale locale)
field
value in the given style
and locale
. From source file:arun.com.popularmovies.util.Utility.java
public static String getReleaseDate(String date) { if (TextUtils.isEmpty(date)) return ""; try {//from ww w . j a v a2 s . c om Calendar calendar = Calendar.getInstance(); calendar.setTime(new SimpleDateFormat("yyyy-MM-dd", Locale.ENGLISH).parse(date)); return calendar.get(Calendar.DATE) + " " + calendar.getDisplayName(Calendar.MONTH, Calendar.LONG, Locale.ENGLISH) + " " + calendar.get(Calendar.YEAR); } catch (ParseException e) { return date; } }
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" *//*from ww w. j a v a2 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:net.menthor.editor.v2.util.Util.java
public static String getCompilationDateMessage() { DateFormat dateFormat = new SimpleDateFormat("d, yyyy"); Date date = new Date(); Calendar c = Calendar.getInstance(); return c.getDisplayName(Calendar.MONTH, Calendar.LONG, Locale.ENGLISH) + " " + dateFormat.format(date); }
From source file:com.philliphsu.bottomsheetpickers.date.PagingDayPickerView.java
private static String getMonthAndYearString(CalendarDay day) { Calendar cal = Calendar.getInstance(); cal.set(day.year, day.month, day.day); StringBuffer sbuf = new StringBuffer(); sbuf.append(cal.getDisplayName(Calendar.MONTH, Calendar.LONG, Locale.getDefault())); sbuf.append(" "); sbuf.append(YEAR_FORMAT.format(cal.getTime())); return sbuf.toString(); }
From source file:com.kunze.androidlocaltodo.TaskActivityFragment.java
private static void SetFriendlyDueDateText(TextView dueDateView, Calendar dueDate) { SimpleDateFormat dateFormatDisplay = new SimpleDateFormat("MM-dd-yyyy", Locale.US); Calendar now = Calendar.getInstance(); int nowDay = TaskDatabase.ConvertDateToInt(now); int dueDay = TaskDatabase.ConvertDateToInt(dueDate); int dayDiff = nowDay - dueDay; if (dayDiff == 0) { dueDateView.setText("Today"); dueDateView.setTextColor(Color.RED); } else if (dueDate.before(now)) { dueDateView.setText("+ " + dayDiff + " days!"); dueDateView.setTextColor(Color.RED); } else if (dayDiff > -7) { dueDateView.setText(dueDate.getDisplayName(Calendar.DAY_OF_WEEK, Calendar.SHORT, Locale.US)); dueDateView.setTextColor(Color.BLACK); } else if (dayDiff > -14) { dueDateView.setText("Next " + dueDate.getDisplayName(Calendar.DAY_OF_WEEK, Calendar.SHORT, Locale.US)); dueDateView.setTextColor(Color.BLACK); } else {/*from ww w . j a v a 2 s . co m*/ dueDateView.setText(dateFormatDisplay.format(dueDate.getTime())); dueDateView.setTextColor(Color.BLACK); } }
From source file:com.personal.coine.scorpion.jxnuhelper.view.activity.SchoolCalendarActivity.java
@Override public void onScrollToDate(Calendar calendar) { actionBar.setTitle(calendar.getDisplayName(Calendar.MONTH, Calendar.LONG, Locale.CHINA)); }
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 ww.j a va 2 s . 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:org.aksw.simba.bengal.triple2nl.converter.LiteralConverter.java
private String convertDateLiteral(LiteralLabel lit) { RDFDatatype dt = lit.getDatatype();/*w w w . jav a 2s.com*/ String s = lit.getLexicalForm(); try { Object value = lit.getValue(); if (value instanceof XSDDateTime) { Calendar calendar = ((XSDDateTime) value).asCalendar(); if (dt.equals(XSDDatatype.XSDgMonth)) { s = calendar.getDisplayName(Calendar.MONTH, Calendar.LONG, ENGLISH_LOCAL); } else if (dt.equals(XSDDatatype.XSDgMonthDay)) { s = calendar.get(Calendar.DAY_OF_MONTH) + calendar.getDisplayName(Calendar.MONTH, Calendar.LONG, ENGLISH_LOCAL); } else if (dt.equals(XSDDatatype.XSDgYearMonth)) { s = calendar.getDisplayName(Calendar.MONTH, Calendar.LONG, ENGLISH_LOCAL) + " " + calendar.get(Calendar.YEAR); } else if (dt.equals(XSDDatatype.XSDgYear)) { s = "" + calendar.get(Calendar.YEAR); } else { s = calendar.getDisplayName(Calendar.MONTH, Calendar.LONG, ENGLISH_LOCAL) + " " + calendar.get(Calendar.DAY_OF_MONTH) + ", " + calendar.get(Calendar.YEAR); // dateFormat.format(calendar.getTime()); } } } catch (DatatypeFormatException | IllegalDateTimeFieldException e) { logger.error("Conversion of date literal " + lit + " failed. Reason: " + e.getMessage()); // fallback // DateTime time = ISODateTimeFormat.dateTime DateTime time; try { time = ISODateTimeFormat.dateTimeParser().parseDateTime(lit.getLexicalForm()); s = time.toString("MMMM dd, yyyy"); } catch (Exception e1) { try { time = ISODateTimeFormat.localDateParser().parseDateTime(lit.getLexicalForm()); s = time.toString("MMMM dd, yyyy"); } catch (Exception e2) { e2.printStackTrace(); time = ISODateTimeFormat.dateParser().parseDateTime(lit.getLexicalForm()); s = time.toString("MMMM dd, yyyy"); } } } return s; }
From source file:calendar.services.transformers.EntryToDayTransformer.java
@Override public DaySummary transform(List<Entry> entryList) { BigDecimal total = new BigDecimal(0); Calendar cal = Calendar.getInstance(); cal.setTime(this.date); if (!entryList.isEmpty()) { daySummary.setEntries(entryList); total = entryList.stream().map((x) -> x.getHours()).reduce((x, y) -> x.add(y)).get(); }//from w ww. j a v a 2 s.c om daySummary.setDay(cal.getDisplayName(Calendar.DAY_OF_WEEK, Calendar.SHORT, Locale.UK)); daySummary.setTotal(total); return daySummary; }
From source file:de.codesourcery.eve.skills.ui.utils.CalendarWidget.java
private String getWeekDayName(Date date) { Calendar calendar = Calendar.getInstance(); calendar.setTime(date);//from w ww .ja v a 2s . c o m return calendar.getDisplayName(Calendar.DAY_OF_WEEK, Calendar.LONG, Locale.getDefault()); }