Java Code Examples for java.util.Calendar#getDisplayName()
The following examples show how to use
java.util.Calendar#getDisplayName() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: Bug6448234.java From TencentKona-8 with GNU General Public License v2.0 | 6 votes |
public static void main(String[] args) { Calendar jcal = Calendar.getInstance(new Locale("ja", "JP", "JP")); Calendar gcal = Calendar.getInstance(Locale.US); for (int i = SUNDAY; i <= SATURDAY; i++) { jcal.set(DAY_OF_WEEK, i); gcal.set(DAY_OF_WEEK, i); // Test LONG String j = jcal.getDisplayName(DAY_OF_WEEK, LONG, Locale.US); String g = gcal.getDisplayName(DAY_OF_WEEK, LONG, Locale.US); if (!j.equals(g)) { throw new RuntimeException("Got " + j + ", expected " + g); } // Test SHORT j = jcal.getDisplayName(DAY_OF_WEEK, SHORT, Locale.US); g = gcal.getDisplayName(DAY_OF_WEEK, SHORT, Locale.US); if (!j.equals(g)) { throw new RuntimeException("Got " + j + ", expected " + g); } } }
Example 2
Source File: Bug6448234.java From jdk8u_jdk with GNU General Public License v2.0 | 6 votes |
public static void main(String[] args) { Calendar jcal = Calendar.getInstance(new Locale("ja", "JP", "JP")); Calendar gcal = Calendar.getInstance(Locale.US); for (int i = SUNDAY; i <= SATURDAY; i++) { jcal.set(DAY_OF_WEEK, i); gcal.set(DAY_OF_WEEK, i); // Test LONG String j = jcal.getDisplayName(DAY_OF_WEEK, LONG, Locale.US); String g = gcal.getDisplayName(DAY_OF_WEEK, LONG, Locale.US); if (!j.equals(g)) { throw new RuntimeException("Got " + j + ", expected " + g); } // Test SHORT j = jcal.getDisplayName(DAY_OF_WEEK, SHORT, Locale.US); g = gcal.getDisplayName(DAY_OF_WEEK, SHORT, Locale.US); if (!j.equals(g)) { throw new RuntimeException("Got " + j + ", expected " + g); } } }
Example 3
Source File: Bug6448234.java From openjdk-jdk9 with GNU General Public License v2.0 | 6 votes |
public static void main(String[] args) { Calendar jcal = Calendar.getInstance(new Locale("ja", "JP", "JP")); Calendar gcal = Calendar.getInstance(Locale.US); for (int i = SUNDAY; i <= SATURDAY; i++) { jcal.set(DAY_OF_WEEK, i); gcal.set(DAY_OF_WEEK, i); // Test LONG String j = jcal.getDisplayName(DAY_OF_WEEK, LONG, Locale.US); String g = gcal.getDisplayName(DAY_OF_WEEK, LONG, Locale.US); if (!j.equals(g)) { throw new RuntimeException("Got " + j + ", expected " + g); } // Test SHORT j = jcal.getDisplayName(DAY_OF_WEEK, SHORT, Locale.US); g = gcal.getDisplayName(DAY_OF_WEEK, SHORT, Locale.US); if (!j.equals(g)) { throw new RuntimeException("Got " + j + ", expected " + g); } } }
Example 4
Source File: TimeUtils.java From jellyfin-androidtv with GNU General Public License v2.0 | 6 votes |
public static String getFriendlyDate(Date date, boolean relative) { Calendar cal = Calendar.getInstance(); cal.setTime(date); Calendar now = Calendar.getInstance(); if (cal.get(Calendar.YEAR) == now.get(Calendar.YEAR)) { if (cal.get(Calendar.DAY_OF_YEAR) == now.get(Calendar.DAY_OF_YEAR)) { return TvApp.getApplication().getString(R.string.lbl_today); } if (cal.get(Calendar.DAY_OF_YEAR) == now.get(Calendar.DAY_OF_YEAR) + 1) { return TvApp.getApplication().getString(R.string.lbl_tomorrow); } if (cal.get(Calendar.DAY_OF_YEAR) < now.get(Calendar.DAY_OF_YEAR) + 7 && cal.get(Calendar.DAY_OF_YEAR) > now.get(Calendar.DAY_OF_YEAR)) { return cal.getDisplayName(Calendar.DAY_OF_WEEK, Calendar.LONG, Locale.getDefault()); } if (relative) { return TvApp.getApplication().getString(R.string.lbl_in_x_days, cal.get(Calendar.DAY_OF_YEAR) - now.get(Calendar.DAY_OF_YEAR)); } } return DateFormat.getDateFormat(TvApp.getApplication()).format(date); }
Example 5
Source File: Bug6448234.java From dragonwell8_jdk with GNU General Public License v2.0 | 6 votes |
public static void main(String[] args) { Calendar jcal = Calendar.getInstance(new Locale("ja", "JP", "JP")); Calendar gcal = Calendar.getInstance(Locale.US); for (int i = SUNDAY; i <= SATURDAY; i++) { jcal.set(DAY_OF_WEEK, i); gcal.set(DAY_OF_WEEK, i); // Test LONG String j = jcal.getDisplayName(DAY_OF_WEEK, LONG, Locale.US); String g = gcal.getDisplayName(DAY_OF_WEEK, LONG, Locale.US); if (!j.equals(g)) { throw new RuntimeException("Got " + j + ", expected " + g); } // Test SHORT j = jcal.getDisplayName(DAY_OF_WEEK, SHORT, Locale.US); g = gcal.getDisplayName(DAY_OF_WEEK, SHORT, Locale.US); if (!j.equals(g)) { throw new RuntimeException("Got " + j + ", expected " + g); } } }
Example 6
Source File: S.java From BaldPhone with Apache License 2.0 | 6 votes |
public static String stringTimeFromLong(@NonNull Context context, long timeStamp, boolean withHoursAndMinutes) { final DateTime now = DateTime.now(); //immutable //time will be before now. so this is checking if event occurred today final DateTime dateTime = new DateTime(timeStamp); Calendar c = Calendar.getInstance(); c.setTime(dateTime.toDate()); if (dateTime.isAfter(now.withMillisOfDay(0))) { return withHoursAndMinutes ? S.numberToAlarmString(dateTime.getHourOfDay(), dateTime.getMinuteOfHour()) : context.getString(R.string.today) ; } else if (dateTime.isAfter(now.withMillisOfDay(0).minusDays(1))) { return withHoursAndMinutes ? String.format("%s %s", context.getString(R.string.yesterday), S.numberToAlarmString(dateTime.getHourOfDay(), dateTime.getMinuteOfHour())) : context.getString(R.string.yesterday); } else if (dateTime.isAfter(now.withMillisOfDay(0).withDayOfWeek(1))) { return c.getDisplayName(Calendar.DAY_OF_WEEK, Calendar.LONG, Locale.getDefault()); } else { return new SimpleDateFormat("dd/MM/yyyy", Locale.getDefault()).format(timeStamp); } }
Example 7
Source File: DatePickerDialog.java From material with Apache License 2.0 | 5 votes |
@Override public void onDateChanged(int oldDay, int oldMonth, int oldYear, int newDay, int newMonth, int newYear) { if(mDaySelectMode) mYearPicker.setYear(newYear); if(newDay < 0 || newMonth < 0 || newYear < 0){ mWeekDay = null; mMonth = null; mDay = null; mYear = null; } else { Calendar cal = mDatePicker.getCalendar(); cal.set(Calendar.YEAR, newYear); cal.set(Calendar.MONTH, newMonth); cal.set(Calendar.DAY_OF_MONTH, newDay); mWeekDay = cal.getDisplayName(Calendar.DAY_OF_WEEK, Calendar.LONG, Locale.getDefault()); mMonth = cal.getDisplayName(Calendar.MONTH, Calendar.SHORT, Locale.getDefault()); mDay = String.format(DAY_FORMAT, newDay); mYear = String.format(YEAR_FORMAT, newYear); if(oldMonth != newMonth || oldYear != newYear) mDatePicker.goTo(newMonth, newYear); } mLocationDirty = true; invalidate(0, 0, mHeaderRealWidth, mHeaderPrimaryRealHeight + mHeaderSecondaryHeight); if(mOnDateChangedListener != null) mOnDateChangedListener.onDateChanged(oldDay, oldMonth, oldYear, newDay, newMonth, newYear); }
Example 8
Source File: DayPickerView.java From MaterialDateRangePicker with Apache License 2.0 | 5 votes |
private static String getMonthAndYearString(MonthAdapter.CalendarDay day) { Calendar cal = Calendar.getInstance(); cal.set(day.year, day.month, day.day); String sbuf = ""; sbuf += cal.getDisplayName(Calendar.MONTH, Calendar.LONG, Locale.getDefault()); sbuf += " "; sbuf += YEAR_FORMAT.format(cal.getTime()); return sbuf; }
Example 9
Source File: DayPickerView.java From AlarmOn with Apache License 2.0 | 5 votes |
private static String getMonthAndYearString(MonthAdapter.CalendarDay day) { Calendar cal = Calendar.getInstance(); cal.set(day.year, day.month, day.day); String sbuf = ""; sbuf += cal.getDisplayName(Calendar.MONTH, Calendar.LONG, Locale.getDefault()); sbuf += " "; sbuf += YEAR_FORMAT.format(cal.getTime()); return sbuf; }
Example 10
Source File: DayPickerView.java From date_picker_converter with Apache License 2.0 | 5 votes |
private static String getMonthAndYearString(MonthAdapter.CalendarDay day, Locale locale) { Calendar cal = Calendar.getInstance(); cal.set(day.year, day.month, day.day); String sbuf = ""; sbuf += cal.getDisplayName(Calendar.MONTH, Calendar.LONG, locale); sbuf += " "; sbuf += YEAR_FORMAT.format(cal.getTime()); return sbuf; }
Example 11
Source File: HelperCalander.java From iGap-Android with GNU Affero General Public License v3.0 | 5 votes |
public static String getArabicCalender(int year, int mounth, int day) { GregorianCalendar gCal = new GregorianCalendar(year, mounth, day); Locale ar = new Locale("ar"); Calendar uCal = new UmmalquraCalendar(ar); uCal.setTime(gCal.getTime()); // Used to properly format 'yy' pattern uCal.get(Calendar.YEAR); // 1435 uCal.getDisplayName(Calendar.MONTH, Calendar.LONG, ar); // رجب uCal.get(Calendar.DAY_OF_MONTH); String time = uCal.get(Calendar.YEAR) + "/" + uCal.getDisplayName(Calendar.MONTH, Calendar.LONG, ar) + "/" + uCal.get(Calendar.DAY_OF_MONTH); return isLanguageArabic ? convertToUnicodeFarsiNumber(time) : time; }
Example 12
Source File: StringUtils.java From letv with Apache License 2.0 | 5 votes |
private static String getWeekName(Calendar calendar) { String name = calendar.getDisplayName(7, 1, Locale.CHINESE); if (TextUtils.isEmpty(name)) { return ""; } return name.replace(LetvUtils.getString(R.string.week_xinqi), LetvUtils.getString(R.string.week_zhou)); }
Example 13
Source File: Time.java From NYU-BusTracker-Android with Apache License 2.0 | 5 votes |
private TimeOfWeek getCurrentTimeOfWeek() { Calendar rightNow = Calendar.getInstance(); rightNow.setTimeZone(TimeZone.getTimeZone("America/New_York")); String dayOfWeek = rightNow.getDisplayName(Calendar.DAY_OF_WEEK, Calendar.LONG, Locale.getDefault()); TimeOfWeek timeOfWeek = TimeOfWeek.Weekday; if (dayOfWeek.equals("Saturday") || dayOfWeek.equals("Sunday")) timeOfWeek = TimeOfWeek.Weekend; else if (dayOfWeek.equals("Friday")) timeOfWeek = TimeOfWeek.Friday; return timeOfWeek; }
Example 14
Source File: DateTimeUtils.java From Deadline with GNU General Public License v3.0 | 5 votes |
public static String getCurrentDateTimeName(int field) { Calendar calendar = Calendar.getInstance(); if (field == Calendar.YEAR) { return String.valueOf(calendar.get(Calendar.YEAR)); } else { return calendar.getDisplayName(field, Calendar.SHORT, Locale.getDefault()); } }
Example 15
Source File: HelperCalander.java From iGap-Android with GNU Affero General Public License v3.0 | 4 votes |
public static String convertEnglishMonthNameToArabic(int month) { Calendar cal = new UmmalquraCalendar(); return cal.getDisplayName(Calendar.MONTH, Calendar.SHORT, new Locale("ar")); }
Example 16
Source File: HelperCalander.java From iGap-Android with GNU Affero General Public License v3.0 | 4 votes |
private static String getArabicStringDay(int dayOfWeek) { Calendar cal = new UmmalquraCalendar(); return cal.getDisplayName(Calendar.DAY_OF_WEEK, Calendar.LONG, new Locale("ar")); }
Example 17
Source File: SchedulingPickerImpl.java From netbeans with Apache License 2.0 | 4 votes |
@NbBundle.Messages({ "# {0} - date from", "# {1} - date until", "CTL_SpecificDates={0} - {1}" }) private static String toDisplayable (IssueScheduleInfo info) { Date date = info.getDate(); int interval = info.getInterval(); Calendar cal = Calendar.getInstance(); stripTime(cal); Calendar scheduleDay = Calendar.getInstance(); scheduleDay.setTime(date); stripTime(scheduleDay); if (interval <= 1) { String dayName = scheduleDay.getDisplayName(Calendar.DAY_OF_WEEK, Calendar.LONG, Locale.getDefault()); for (int i = 0; i < 7; ++i) { if (cal.getTime().equals(scheduleDay.getTime())) { if (i == 0) { dayName = Bundle.CTL_Today(dayName); } return dayName; } cal.add(Calendar.DATE, 1); } return DATE_FORMAT.format(date); } else { scheduleDay.setTime(date); stripTime(scheduleDay); Calendar until = Calendar.getInstance(); until.setTime(date); stripTime(until); until.add(Calendar.DATE, interval); if (isThisWeek(scheduleDay, until)) { return Bundle.CTL_ThisWeek(); } else if (isNextWeek(scheduleDay, until)) { return Bundle.CTL_NextWeek(); } else { return Bundle.CTL_SpecificDates(DATE_FORMAT.format(scheduleDay.getTime()), DATE_FORMAT.format(until.getTime())); } } }
Example 18
Source File: GraphsFragment.java From Weather with GNU General Public License v3.0 | 4 votes |
public String getDay(long dt) { dt *= 1000; Calendar c = Calendar.getInstance(); c.setTime(new Date(dt)); return c.getDisplayName(Calendar.DAY_OF_WEEK , Calendar.SHORT , new Locale(new Prefs(getActivity()).getLanguage())); }
Example 19
Source File: TimeUtils.java From chat21-android-sdk with GNU Affero General Public License v3.0 | 4 votes |
public static String getDayOfWeek(Date date) { Calendar cal = Calendar.getInstance(); cal.setTime(date); return cal.getDisplayName(Calendar.DAY_OF_WEEK, Calendar.LONG, Locale.getDefault()); }
Example 20
Source File: RecurringPickerDialog.java From material with Apache License 2.0 | 4 votes |
private void updateRecurringData(){ Calendar cal = Calendar.getInstance(); cal.setTimeInMillis(mRecurring.getStartTime()); int order = Recurring.getWeekDayOrderNum(cal); String dayOfWeek = cal.getDisplayName(Calendar.DAY_OF_WEEK, Calendar.LONG, Locale.getDefault()); int formattedTextId = MONTH_SAME_WEEKDAY[(order + 1) % MONTH_SAME_WEEKDAY.length]; mSameWeekdayRadioButton.setText(getContext().getResources().getString(formattedTextId, dayOfWeek)); mPeriodEditText.setText(String.valueOf(mRecurring.getPeriod())); if(mRecurring.getRepeatMode() == Recurring.REPEAT_WEEKLY) { for(int i = Calendar.SUNDAY; i <= Calendar.SATURDAY; i++) mWeekView.setSelected(i, mRecurring.isEnabledWeekday(i), true); } else{ int day = cal.get(Calendar.DAY_OF_WEEK); for(int i = Calendar.SUNDAY; i <= Calendar.SATURDAY; i++) mWeekView.setSelected(i, i == day, true); if(mRecurring.getRepeatMode() == Recurring.REPEAT_MONTHLY){ mSameDayRadioButton.setCheckedImmediately(mRecurring.getMonthRepeatType() == Recurring.MONTH_SAME_DAY); mSameWeekdayRadioButton.setCheckedImmediately(mRecurring.getMonthRepeatType() == Recurring.MONTH_SAME_WEEKDAY); } else{ mSameDayRadioButton.setCheckedImmediately(true); mSameWeekdayRadioButton.setCheckedImmediately(false); } } if(mModeSpinner.getSelectedItemPosition() != mRecurring.getRepeatMode()) mModeSpinner.setSelection(mRecurring.getRepeatMode()); else onModeSelected(mRecurring.getRepeatMode()); mEndNumEditText.setText(String.valueOf(mRecurring.getEndMode() == Recurring.END_FOR_EVENT ? mRecurring.getEventNumber() : 10)); long date = mRecurring.getEndMode() == Recurring.END_UNTIL_DATE ? mRecurring.getEndDate() : (Math.max(System.currentTimeMillis(), mRecurring.getStartTime()) + 86400000L * 31); mEndDateButton.setText(mDateFormat.format(new Date(date))); mEndDateButton.setTag(date); if(mEndSpinner.getSelectedItemPosition() != mRecurring.getEndMode()) mEndSpinner.setSelection(mRecurring.getEndMode()); else onEndSelected(mRecurring.getEndMode()); }