本文整理了Java中java.util.Calendar.getDisplayName()
方法的一些代码示例,展示了Calendar.getDisplayName()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Calendar.getDisplayName()
方法的具体详情如下:
包路径:java.util.Calendar
类名称:Calendar
方法名:getDisplayName
[英]Returns a human-readable string for the value of fieldusing the given style and locale. If no string is available, returns null. The value is retrieved by invoking get(field).
For example, getDisplayName(MONTH, SHORT, Locale.US) will return "Jan" while getDisplayName(MONTH, LONG, Locale.US) will return "January".
[中]使用给定的样式和区域设置,返回字段值的可读字符串。如果没有可用字符串,则返回null。通过调用get(field)检索该值。
例如,getDisplayName(MONTH,SHORT,Locale.US)将返回“Jan”,而getDisplayName(MONTH,LONG,Locale.US)将返回“一月”。
代码示例来源:origin: k9mail/k-9
String getDateFormatted(String format) {
calendar.setTimeInMillis(date);
return String.format(format,
calendar.get(Calendar.DAY_OF_MONTH),
calendar.getDisplayName(Calendar.MONTH, Calendar.SHORT, Locale.getDefault()));
}
}
代码示例来源:origin: rey5137/material
private void calculateMonthView(){
mCalendar.set(Calendar.DAY_OF_MONTH, 1);
mCalendar.set(Calendar.MONTH, mMonth);
mCalendar.set(Calendar.YEAR, mYear);
mMaxDay = mCalendar.getActualMaximum(Calendar.DAY_OF_MONTH);
int dayOfWeek = mCalendar.get(Calendar.DAY_OF_WEEK);
mFirstDayCol = dayOfWeek < mFirstDayOfWeek ? dayOfWeek + 7 - mFirstDayOfWeek : dayOfWeek - mFirstDayOfWeek;
mMonthText = mCalendar.getDisplayName(Calendar.MONTH, Calendar.LONG, Locale.getDefault()) + " " + String.format(YEAR_FORMAT, mYear);
}
代码示例来源:origin: stackoverflow.com
Calendar c = Calendar.getInstance();
System.out.println(c.getDisplayName(Calendar.MONTH, Calendar.LONG, Locale.ENGLISH ) );
System.out.println(c.getDisplayName(Calendar.MONTH, Calendar.LONG, Locale.FRANCE ) );
System.out.println(c.getDisplayName(Calendar.MONTH, Calendar.LONG, new Locale("ar") ) );
System.out.println(c.getDisplayName(Calendar.MONTH, Calendar.LONG, new Locale("ar", "SY") ) );
System.out.println(c.getTime().toString());
代码示例来源:origin: iSoron/uhabits
private void drawMonthDayLabels(Canvas canvas) {
int y = MONTH_HEADER_SIZE - (MONTH_DAY_LABEL_TEXT_SIZE / 2);
int dayWidthHalf = (mWidth - mPadding * 2) / (mNumDays * 2);
for (int i = 0; i < mNumDays; i++) {
int calendarDay = (i + mWeekStart) % mNumDays;
int x = (2 * i + 1) * dayWidthHalf + mPadding;
mDayLabelCalendar.set(Calendar.DAY_OF_WEEK, calendarDay);
canvas.drawText(mDayLabelCalendar.getDisplayName(Calendar.DAY_OF_WEEK, Calendar.SHORT,
Locale.getDefault()).toUpperCase(Locale.getDefault()), x, y,
mMonthDayLabelPaint);
}
}
代码示例来源:origin: iSoron/uhabits
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();
}
代码示例来源:origin: iSoron/uhabits
private static String[] getDayNames(int format)
{
String[] wdays = new String[7];
Calendar day = new GregorianCalendar();
day.set(DAY_OF_WEEK, Calendar.SATURDAY);
for (int i = 0; i < wdays.length; i++)
{
wdays[i] =
day.getDisplayName(DAY_OF_WEEK, format, getLocale());
day.add(DAY_OF_MONTH, 1);
}
return wdays;
}
代码示例来源:origin: iSoron/uhabits
/**
* @return array with weekday names starting according to locale settings,
* e.g. [Mo,Di,Mi,Do,Fr,Sa,So] in Germany
*/
public static String[] getLocaleDayNames(int format)
{
String[] days = new String[7];
Calendar calendar = new GregorianCalendar();
calendar.set(DAY_OF_WEEK, calendar.getFirstDayOfWeek());
for (int i = 0; i < days.length; i++)
{
days[i] = calendar.getDisplayName(DAY_OF_WEEK, format,
getLocale());
calendar.add(DAY_OF_MONTH, 1);
}
return days;
}
代码示例来源:origin: rey5137/material
@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);
}
代码示例来源:origin: iSoron/uhabits
private void updateDisplay(boolean announce) {
if (mDayOfWeekView != null) {
mDayOfWeekView.setText(mCalendar.getDisplayName(Calendar.DAY_OF_WEEK, Calendar.LONG,
Locale.getDefault()).toUpperCase(Locale.getDefault()));
}
mSelectedMonthTextView.setText(mCalendar.getDisplayName(Calendar.MONTH, Calendar.SHORT,
Locale.getDefault()).toUpperCase(Locale.getDefault()));
mSelectedDayTextView.setText(DAY_FORMAT.format(mCalendar.getTime()));
mYearView.setText(YEAR_FORMAT.format(mCalendar.getTime()));
// Accessibility.
long millis = mCalendar.getTimeInMillis();
mAnimator.setDateMillis(millis);
int flags = DateUtils.FORMAT_SHOW_DATE | DateUtils.FORMAT_NO_YEAR;
String monthAndDayText = DateUtils.formatDateTime(getActivity(), millis, flags);
mMonthAndDayView.setContentDescription(monthAndDayText);
if (announce) {
flags = DateUtils.FORMAT_SHOW_DATE | DateUtils.FORMAT_SHOW_YEAR;
String fullDateText = DateUtils.formatDateTime(getActivity(), millis, flags);
Utils.tryAccessibilityAnnounce(mAnimator, fullDateText);
}
}
代码示例来源:origin: wdullaer/MaterialDateTimePicker
mDatePickerHeaderView.setText(mTitle);
else {
mDatePickerHeaderView.setText(mCalendar.getDisplayName(Calendar.DAY_OF_WEEK, Calendar.LONG,
mLocale));
代码示例来源:origin: rey5137/material
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));
代码示例来源:origin: stackoverflow.com
TimeZone timezone = TimeZone.getDefault();
Calendar calendar = new GregorianCalendar(timezone);
calendar.set(year, month, day, hour, minute, second);
String monthName=calendar.getDisplayName(Calendar.MONTH, Calendar.SHORT, Locale.getDefault());//Locale.US);
String dayName=calendar.getDisplayName(Calendar.DAY_OF_WEEK, Calendar.SHORT, Locale.getDefault());//Locale.US);
代码示例来源:origin: stackoverflow.com
Calendar cal = Calendar.getInstance();
cal.set(Calendar.DAY_OF_YEAR, dayOfYear); // Set the day of the year value
String day = cal.getDisplayName(Calendar.DAY_OF_WEEK, Calendar.LONG, Locale.US);
// Use Calendar.SHORT for abbreviated names or .LONG for full names
// and be sure to change the locale as necessary
代码示例来源:origin: grzegorznittner/chanu
protected String twelveHourString(Calendar postCal) {
int hour = postCal.get(Calendar.HOUR_OF_DAY);
int min = postCal.get(Calendar.MINUTE);
return (hour == 0 ? 12 : hour)
+ ":"
+ (min < 10 ? "0" : "")
+ min
+ " "
+ postCal.getDisplayName(Calendar.AM_PM, Calendar.SHORT, Locale.getDefault());
}
代码示例来源:origin: stackoverflow.com
public class PropertyInterceptor implements MethodInterceptor {
public Object invoke(MethodInvocation invocation) throws Throwable {
// For example prevent the classes annotated with @Property
// from being called on weekends
Calendar today = new GregorianCalendar();
if (today.getDisplayName(DAY_OF_WEEK, LONG, ENGLISH).startsWith("S")) {
throw new IllegalStateException(
invocation.getMethod().getName() + " not allowed on weekends!");
}
return invocation.proceed();
}
}
代码示例来源:origin: Gwokhov/Deadline
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());
}
}
代码示例来源:origin: stackoverflow.com
final Calendar cal = Calendar.getInstance();
java.text.DateFormat df= DateFormat.getMediumDateFormat(mCtx);
java.text.DateFormat df1=DateFormat.getTimeFormat(mCtx);
String date = (df.format(timeStamp).toString());
String time=df1.format(timeStamp);
cal.setTimeInMillis(timeStamp);
int messageYear=cal.get(Calendar.YEAR);
int month=cal.get(Calendar.MONTH);
int dates=cal.get(Calendar.DATE);
Locale locale=Locale.getDefault();
String monthName=cal.getDisplayName(Calendar.MONTH, Calendar.SHORT , locale);
String date = monthName+" "+dates+"\n"+time;
代码示例来源:origin: stackoverflow.com
Scanner input= new Scanner(System.in);
System.out.print("Enter Year:");
int year = input.nextInt();
Calendar cal = Calendar.getInstance();
for (int i=0; i<12; i++) {
cal.set(year, i, 1);
System.out.printf( "the first day of %s is %s\n",
cal.getDisplayName(Calendar.MONTH, Calendar.LONG, Locale.getDefault()),
cal.getDisplayName(Calendar.DAY_OF_WEEK, Calendar.LONG, Locale.getDefault()) );
}//end for i
代码示例来源:origin: stackoverflow.com
try {
Scanner s = new Scanner(System.in);
System.out.println("Please enter your birthday. Format: DD.MM.YYYY");
String bday = s.nextLine();
Date date = new SimpleDateFormat("dd.MM.yyyy").parse(bday);
Calendar birthday = Calendar.getInstance();
birthday.setTime(date);
String weekday = birthday.getDisplayName(Calendar.DAY_OF_WEEK, Calendar.LONG, Locale.getDefault());
System.out.println("Weekday of birth: " + weekday); // wrong }
} catch (ParseException exp) {
exp.printStackTrace();
}
代码示例来源:origin: EvoSuite/evosuite
public String getDisplayName(int field, int style, Locale locale) {
Capturer.capture(Instrumenter.CAPTURE_ID_JAVA_UTIL_CALENDAR, this, "getDisplayName", "(IILjava/util/Locale;)Ljava/lang/String;", new Object[] {field, style, locale});
String ret = wrappedCalendar.getDisplayName(field, style, locale);
Capturer.enable(Instrumenter.CAPTURE_ID_JAVA_UTIL_CALENDAR, this, ret);
return ret;
}
内容来源于网络,如有侵权,请联系作者删除!