本文整理匯總了Java中java.util.Calendar.getDisplayName方法的典型用法代碼示例。如果您正苦於以下問題:Java Calendar.getDisplayName方法的具體用法?Java Calendar.getDisplayName怎麽用?Java Calendar.getDisplayName使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類java.util.Calendar
的用法示例。
在下文中一共展示了Calendar.getDisplayName方法的14個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: main
import java.util.Calendar; //導入方法依賴的package包/類
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);
}
}
}
示例2: getMonthAndYearString
import java.util.Calendar; //導入方法依賴的package包/類
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;
}
示例3: addToHabits
import java.util.Calendar; //導入方法依賴的package包/類
/**
* Add Habit object to either fulfilledHabits or unfulfilledHabits. Consider the habit finished
* within today as a recent completed habit.
* @param habit Habit object.
* @param today Today.
*/
private void addToHabits(Habit habit, Calendar today) {
boolean notPast = false;
boolean isToday = false;
boolean shouldOccur = false;
Calendar habitDate = habit.getHabitDate();
// https://www.tutorialspoint.com/java/util/calendar_getdisplaynames.htm
Locale locale = Locale.CANADA;
String todayOfWeek = today.getDisplayName(Calendar.DAY_OF_WEEK, Calendar.LONG, locale);
SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy MMM dd");
if (today.after(habitDate)) {
notPast = true;
}
if (dateFormat.format(today.getTime()).equals(habitDate)) {
isToday = true;
}
if (habit.getOccurDays().contains(todayOfWeek)) {
shouldOccur = true;
}
if ((notPast || isToday) && shouldOccur) {
if (habit.getFulfilDate().isEmpty()) {
unfulfilledHabits.add(habit);
} else {
for (Calendar date : habit.getFulfilDate()) {
// if the habit has been fulfilled today
if (dateFormat.format(date.getTime()).equals(dateFormat.format(today.getTime()))) {
fulfilledHabits.add(habit);
break;
}
}
}
}
}
示例4: getTemperatureLabel
import java.util.Calendar; //導入方法依賴的package包/類
private String getTemperatureLabel(long time, String timezone) {
Calendar calendar = Calendar.getInstance();
calendar.setTimeZone(TimeZone.getTimeZone(timezone));
calendar.setTimeInMillis(time * 1000);
return calendar.getDisplayName(Calendar.MONTH, Calendar.SHORT, Locale.getDefault())
+ " " + String.format("%02d", calendar.get(Calendar.DAY_OF_MONTH))
+ " " + String.format("%02d", calendar.get(Calendar.HOUR_OF_DAY))
+ ":" + String.format("%02d", calendar.get(Calendar.MINUTE));
}
示例5: getWeekName
import java.util.Calendar; //導入方法依賴的package包/類
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));
}
示例6: getMonthAndYearString
import java.util.Calendar; //導入方法依賴的package包/類
private static String getMonthAndYearString(CalendarDay day) {
Calendar cal = Calendar.getInstance();
cal.set(day.year, day.month, day.day);
return (("" + cal.getDisplayName(2, 2, Locale.getDefault())) + " ") + YEAR_FORMAT.format
(cal.getTime());
}
示例7: datetimeToStr
import java.util.Calendar; //導入方法依賴的package包/類
String datetimeToStr(Calendar c){
String month = c.getDisplayName(Calendar.MONTH, Calendar.SHORT, Locale.US);
return month+"+"+c.get(Calendar.DAY_OF_MONTH)+"%2C+" + c.get(Calendar.YEAR);
}
示例8: toDisplayable
import java.util.Calendar; //導入方法依賴的package包/類
@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()));
}
}
}
示例9: resolveCalendarFieldName
import java.util.Calendar; //導入方法依賴的package包/類
/**
* Obtains a name of a calendar field with the specified <var>field</var> identifier from the
* given <var>calendar</var> for the specified <var>locale</var>.
* <p>
* <b>Note</b>, that for pre {@link android.os.Build.VERSION_CODES#GINGERBREAD GINGERBREAD} Android
* version and field names listed below, this method will return only English name regardless
* the specified <var>locale</var>:
* <ul>
* <li>{@link Calendar#MONTH}</li>
* <li>{@link Calendar#DAY_OF_WEEK}</li>
* </ul>
*
* @param calendar The calendar from which to obtain the requested field's name.
* @param field The desired field identifier. See {@link Calendar} for field identifiers.
* @param style Style flag for the requested name. One of {@link #CALENDAR_STYLE_SHORT} or
* {@link #CALENDAR_STYLE_LONG}.
* @param locale The locale for which to obtain the requested name. If there is no name available
* for the requested locale, {@link UiConfig#DEFAULT_LOCALE} will be used instead.
* @return Name of the requested calendar field.
*/
@NonNull
@SuppressLint("NewApi")
public static String resolveCalendarFieldName(@NonNull Calendar calendar, int field, int style, @NonNull Locale locale) {
if (!PRE_GINGERBREAD) {
final String name = calendar.getDisplayName(field, style, locale);
return name != null ? name : calendar.getDisplayName(field, style, UiConfig.DEFAULT_LOCALE);
}
switch (field) {
case Calendar.MONTH:
return PRE_GINGERBREAD_MONTH_NAMES[calendar.get(field)];
case Calendar.DAY_OF_WEEK:
return PRE_GINGERBREAD_DAY_NAMES[calendar.get(field) - 1];
}
return "";
}
示例10: addForcastUI
import java.util.Calendar; //導入方法依賴的package包/類
public void addForcastUI(final WeahterDay dayItem) {
int screenW = Resources.getSystem().getDisplayMetrics().widthPixels;
int itemW = screenW / 4;
View layout = LayoutInflater.from(this).inflate(R.layout.sub_item_layout, null);
TextView subDayTv = (TextView) layout.findViewById(R.id.subDayTv);
ImageView subIconTv = (ImageView) layout.findViewById(R.id.subIconTv);
TextView subTempMaxTv = (TextView) layout.findViewById(R.id.subTempMaxTv);
TextView subTempMinTv = (TextView) layout.findViewById(R.id.subTempMinTv);
Calendar cal = Calendar.getInstance();
cal.setTimeInMillis(dayItem.getTimestmp());
String dayOfWeek = cal.getDisplayName(Calendar.DAY_OF_WEEK, Calendar.SHORT, Locale.ENGLISH);
subDayTv.setText(dayOfWeek);
subTempMaxTv.setText("↑" + String.format("%.0f", dayItem.getTempMax()) + "°");
subTempMinTv.setText("↓" + String.format("%.0f", dayItem.getTempMin()) + "°");
subIconTv.getLayoutParams().height = itemW;
subIconTv.setImageResource(dayItem.getIconRes());
final MyData md = new MyData();
final long[] dt = new long[dayItem.getItems().size()];
int i = 0;
for (WeatherItem wi : dayItem.getItems()) {
md.add((float) wi.getTemp());
//md.add(wi.getTimestmp(), (float) wi.getTemp());
dt[i++] = wi.getTimestmp();
}
layout.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
showMainDetails(dayItem);
showGraph(md, dt);
showFullDetails(dayItem);
showMap();
}
});
forcastLL.addView(layout);
}
示例11: getTable
import java.util.Calendar; //導入方法依賴的package包/類
private Object[][] getTable(String portfolioName, int year) {
Calendar current = Calendar.getInstance();
Calendar c = Calendar.getInstance();
int nbrofmonths;
if (year == current.get(Calendar.YEAR)) {
nbrofmonths = Math.min(12, current.get(Calendar.MONTH));
}
else {
nbrofmonths = 12;
}
Object[][] table = new Object[nbrofmonths][columnNames.length];
int row = 0;
Portfolio portfolio = PortfolioFactory.createPortfolio(portfolioName,
current.getTime(), TickerManager
.createTickerManager());
for (int month = 0; month < nbrofmonths; ++month) {
try {
c.set(Calendar.YEAR, year);
c.set(Calendar.MONTH, month);
c.set(Calendar.DATE, 1);
Date startDate = c.getTime();
portfolio.process(startDate);
portfolio.getCombinedBookEntryTable(false);
double value1 = portfolio.getPortfolioValue();
c.set(Calendar.DAY_OF_MONTH,
c.getActualMaximum(Calendar.DAY_OF_MONTH));
Date endDate = null;
if (c.get(Calendar.YEAR) != Calendar.getInstance().get(
Calendar.YEAR) || c.get(Calendar.MONTH) != Calendar.getInstance().get(
Calendar.MONTH)) {
endDate = c.getTime();
} else {
endDate = (Calendar.getInstance().getTime());
}
portfolio.process(endDate);
portfolio.getCombinedBookEntryTable(false);
double value2 = portfolio.getPortfolioValue();
int col = 0;
table[row][col++] = c.getDisplayName(Calendar.MONTH, Calendar.LONG, getLocale());
table[row][col++] = value1;
table[row][col++] = value2;
table[row][col++] = value2 - value1;
table[row][col++] = (value2 - value1)/value1*100.0;
//table[row][col++] = portfolio.getXirr(value1, startDate);
row++;
} catch (NumberFormatException e) {
}
}
return table;
}
示例12: convertDateLiteral
import java.util.Calendar; //導入方法依賴的package包/類
private String convertDateLiteral(LiteralLabel lit) {
RDFDatatype dt = lit.getDatatype();
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, PORTUGUESE_LOCAL);
} else if (dt.equals(XSDDatatype.XSDgMonthDay)) {
s = calendar.get(Calendar.DAY_OF_MONTH)
+ calendar.getDisplayName(Calendar.MONTH, Calendar.LONG, PORTUGUESE_LOCAL);
} else if (dt.equals(XSDDatatype.XSDgYearMonth)) {
s = calendar.getDisplayName(Calendar.MONTH, Calendar.LONG, PORTUGUESE_LOCAL) + " "
+ calendar.get(Calendar.YEAR);
} else if (dt.equals(XSDDatatype.XSDgYear)) {
s = "" + calendar.get(Calendar.YEAR);
} else {
s = calendar.get(Calendar.DAY_OF_MONTH) + " de "
+ calendar.getDisplayName(Calendar.MONTH, Calendar.LONG, PORTUGUESE_LOCAL) + " de "
+ 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("dd 'de' MMMM 'de' YYYY", PORTUGUESE_LOCAL);
} catch (Exception e1) {
try {
time = ISODateTimeFormat.localDateParser().parseDateTime(lit.getLexicalForm());
s = time.toString("dd 'de' MMMM 'de' YYYY", PORTUGUESE_LOCAL);
} catch (Exception e2) {
e2.printStackTrace();
time = ISODateTimeFormat.dateParser().parseDateTime(lit.getLexicalForm());
s = time.toString("dd 'de' MMMM 'de' YYYY", PORTUGUESE_LOCAL);
}
}
}
return s;
}
示例13: convertDateLiteral
import java.util.Calendar; //導入方法依賴的package包/類
private String convertDateLiteral(LiteralLabel lit){
RDFDatatype dt = lit.getDatatype();
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;
}
示例14: convertDateLiteral
import java.util.Calendar; //導入方法依賴的package包/類
private String convertDateLiteral(LiteralLabel lit) {
RDFDatatype dt = lit.getDatatype();
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, FRENCH_LOCAL);
} else if (dt.equals(XSDDatatype.XSDgMonthDay)) {
s = calendar.get(Calendar.DAY_OF_MONTH)
+ calendar.getDisplayName(Calendar.MONTH, Calendar.LONG, FRENCH_LOCAL);
} else if (dt.equals(XSDDatatype.XSDgYearMonth)) {
s = calendar.getDisplayName(Calendar.MONTH, Calendar.LONG, FRENCH_LOCAL) + " "
+ calendar.get(Calendar.YEAR);
} else if (dt.equals(XSDDatatype.XSDgYear)) {
s = "" + calendar.get(Calendar.YEAR);
} else {
s = calendar.get(Calendar.DAY_OF_MONTH) + " "
+ calendar.getDisplayName(Calendar.MONTH, Calendar.LONG, FRENCH_LOCAL) + " "
+ 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("dd MMMM YYYY", FRENCH_LOCAL);
} catch (Exception e1) {
try {
time = ISODateTimeFormat.localDateParser().parseDateTime(lit.getLexicalForm());
s = time.toString("dd MMMM YYYY", FRENCH_LOCAL);
} catch (Exception e2) {
e2.printStackTrace();
time = ISODateTimeFormat.dateParser().parseDateTime(lit.getLexicalForm());
s = time.toString("dd MMMM YYYY", FRENCH_LOCAL);
}
}
}
return s;
}