本文整理汇总了Java中java.text.DateFormat.getDateInstance方法的典型用法代码示例。如果您正苦于以下问题:Java DateFormat.getDateInstance方法的具体用法?Java DateFormat.getDateInstance怎么用?Java DateFormat.getDateInstance使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类java.text.DateFormat
的用法示例。
在下文中一共展示了DateFormat.getDateInstance方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: main
import java.text.DateFormat; //导入方法依赖的package包/类
public static void main(String[] arg) {
int errors = 0;
DateFormat df = DateFormat.getDateInstance(LONG, FINNISH);
Date jan20 = new GregorianCalendar(2015, JANUARY, 20).getTime();
String str = df.format(jan20).toString();
// Extract the month name (locale data dependent)
String month = str.replaceAll(".+\\s([a-z]+)\\s\\d+$", "$1");
if (!month.equals(JAN_FORMAT)) {
errors++;
System.err.println("wrong format month name: got '" + month
+ "', expected '" + JAN_FORMAT + "'");
}
SimpleDateFormat sdf = new SimpleDateFormat("LLLL", FINNISH); // stand-alone month name
month = sdf.format(jan20);
if (!month.equals(JAN_STANDALONE)) {
errors++;
System.err.println("wrong stand-alone month name: got '" + month
+ "', expected '" + JAN_STANDALONE + "'");
}
if (errors > 0) {
throw new RuntimeException();
}
}
示例2: getLocalePatternInfo
import java.text.DateFormat; //导入方法依赖的package包/类
/**
* Retourne un tableau avec les informations sur le format standard des dates et heures.<br>
* [0] = séparateur dans une date, exemple: "."<br>
* [1] = séparateur sous la forme d'une expression regex, exemple: "\."<br>
* [2] = le format d'une date, exemple: "dd.MM.yy"<br>
* [3] = séparateur d'un temps, exemple: ":"<br>
* [4] = séparateur d'un temps sous la forme d'une expression regex, exemple: "\:"<br>
* [5] = le format d'un temps, exemple: "HH:mm:ss"<br>
*
* @return un tableau avec les informations sus-mentionnées
*/
public static String[] getLocalePatternInfo() {
String info[] = new String[6];
DateFormat dateFormat = DateFormat.getDateInstance(DateFormat.SHORT, Locale.getDefault());
FieldPosition yearPosition = new FieldPosition(DateFormat.YEAR_FIELD);
StringBuffer buffer = new StringBuffer();
StringBuffer format = dateFormat.format(getNow(), buffer, yearPosition);
String pattern = new SimpleDateFormat().toPattern();
String datePattern = pattern.substring(0, format.length());
String hourPattern = pattern.substring(format.length() + 1);
// infos sur le format des dates
int yearIdx = yearPosition.getBeginIndex() - 1;
info[0] = format.substring(yearIdx, yearIdx + 1);
info[1] = "\\" + info[0];
info[2] = datePattern;
// infos sur le format des heures
info[3] = hourPattern.substring(2, 3);
info[4] = "\\" + info[3];
info[5] = hourPattern + info[3] + "ss";
return info;
}
示例3: getBuildViewModelAtCursor
import java.text.DateFormat; //导入方法依赖的package包/类
@NonNull
private BuildViewModel getBuildViewModelAtCursor(Cursor cursor) {
long buildId = cursor.getLong(cursor.getColumnIndex(DbAdapter.KEY_BUILD_ORDER_ID));
String buildName = cursor.getString(cursor.getColumnIndex(DbAdapter.KEY_NAME));
String dateStr = cursor.getString(cursor.getColumnIndex(DbAdapter.KEY_CREATED));
String formattedDateStr = "";
if (!TextUtils.isEmpty(dateStr)) {
Date date;
try {
date = DbAdapter.DATE_FORMAT.parse(dateStr);
DateFormat df = DateFormat.getDateInstance(DateFormat.LONG);
formattedDateStr = df.format(date);
} catch (ParseException e) {
e.printStackTrace();
}
}
int vsFactionId = cursor.getInt(cursor.getColumnIndex(DbAdapter.KEY_VS_FACTION_ID));
@StringRes int vsFactionStringId = (vsFactionId == 0) ? R.string.race_any : DbAdapter.getFactionName(vsFactionId);
String vsRaceFormatted = context.getString(R.string.build_row_vs_race_template, context.getString(vsFactionStringId));
return new BuildViewModel(buildId, buildName, formattedDateStr, vsRaceFormatted);
}
示例4: getEpisodeDateFormatted
import java.text.DateFormat; //导入方法依赖的package包/类
/** returns null if the date is not valid */
public String getEpisodeDateFormatted() {
if (mEpisodeDate>0) {
Date date = new Date(mEpisodeDate);
if (date != null) {
DateFormat formatter = DateFormat.getDateInstance();
return formatter.format(date);
}
}
return null;
}
示例5: test_date_parse
import java.text.DateFormat; //导入方法依赖的package包/类
@SuppressWarnings("deprecation")
@Test(dataProvider="date")
public void test_date_parse(LocalDate date, FormatStyle dateStyle, int dateStyleOld, Locale locale) {
DateFormat old = DateFormat.getDateInstance(dateStyleOld, locale);
Date oldDate = new Date(date.getYear() - 1900, date.getMonthValue() - 1, date.getDayOfMonth());
String text = old.format(oldDate);
DateTimeFormatter f = builder.appendLocalized(dateStyle, null).toFormatter(locale);
TemporalAccessor parsed = f.parse(text, pos);
assertEquals(pos.getIndex(), text.length());
assertEquals(pos.getErrorIndex(), -1);
assertEquals(LocalDate.from(parsed), date);
}
示例6: testDateFormat
import java.text.DateFormat; //导入方法依赖的package包/类
@Test(dataProvider = "dateFormats")
public void testDateFormat(Locale loc, int style, int year, int month, int date, String expectedString) {
Calendar cal = Calendar.getInstance(loc);
cal.set(year, month-1, date);
// Create date formatter based on requested style and test locale
DateFormat df = DateFormat.getDateInstance(style, loc);
// Test the date format
assertEquals(df.format(cal.getTime()), expectedString);
}
示例7: getFormattedDate
import java.text.DateFormat; //导入方法依赖的package包/类
private static String getFormattedDate() {
Time time = new Time();
time.setToNow();
DateFormat.getDateInstance();
Calendar c = Calendar.getInstance();
SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
String formattedDate = df.format(c.getTime());
return formattedDate;
}
示例8: main
import java.text.DateFormat; //导入方法依赖的package包/类
public static void main(String[] arg)
{
String s = "2003\u5e749\u670826\u65e5"; // "2003y9m26d"
DateFormat df =
DateFormat.getDateInstance(DateFormat.FULL,Locale.JAPANESE);
try {
if ( !s.equals(df.format(df.parse(s))) )
throw new RuntimeException();
} catch (ParseException e) {
throw new RuntimeException();
}
}
示例9: getMondayOFWeek
import java.text.DateFormat; //导入方法依赖的package包/类
public String getMondayOFWeek()
{
weeks = 0;
int mondayPlus = this.getMondayPlus();
GregorianCalendar currentDate = new GregorianCalendar();
currentDate.add(GregorianCalendar.DATE, mondayPlus);
Date monday = currentDate.getTime();
DateFormat df = DateFormat.getDateInstance();
String preMonday = df.format(monday);
return preMonday;
}
示例10: formatDate
import java.text.DateFormat; //导入方法依赖的package包/类
public String formatDate(final Date date) {
if (dateFormat == null) {
dateFormat = DateFormat.getDateInstance(DateFormat.LONG);
}
return dateFormat.format(date);
}
示例11: getCurrentYearFirst
import java.text.DateFormat; //导入方法依赖的package包/类
public static String getCurrentYearFirst() {
int yearPlus = getYearPlus();
GregorianCalendar currentDate = new GregorianCalendar();
currentDate.add(GregorianCalendar.DATE, yearPlus);
Date yearDay = currentDate.getTime();
DateFormat df = DateFormat.getDateInstance();
String preYearDay = df.format(yearDay);
return preYearDay;
}
示例12: EpisodeListDetailedPresenter
import java.text.DateFormat; //导入方法依赖的package包/类
public EpisodeListDetailedPresenter(Context context, ExtendedClickListener listener) {
super(context, AdapterDefaultValuesDetails.INSTANCE, listener);
mNumberFormat = NumberFormat.getInstance();
mNumberFormat.setMinimumFractionDigits(1);
mNumberFormat.setMaximumFractionDigits(1);
mDateFormat = DateFormat.getDateInstance(DateFormat.LONG);
}
示例13: ClaimItemViewHolder
import java.text.DateFormat; //导入方法依赖的package包/类
public ClaimItemViewHolder(final View claimItemCard) {
super(claimItemCard);
this.categoryIcon = claimItemCard.findViewById(R.id.item_category);
this.description = claimItemCard.findViewById(R.id.item_description);
this.amount = claimItemCard.findViewById(R.id.item_amount);
this.timestamp = claimItemCard.findViewById(R.id.item_timestamp);
this.dateFormat = DateFormat.getDateInstance(DateFormat.LONG);
}
示例14: getDateString
import java.text.DateFormat; //导入方法依赖的package包/类
public static String getDateString(Date d, int f) {
DateFormat dateFormat = DateFormat.getDateInstance(f, currentLocale);
return dateFormat.format(d);
}
示例15: showMemoPost
import java.text.DateFormat; //导入方法依赖的package包/类
/**
* @param topic
* @param activeChar
* @param forum
*/
private void showMemoPost(Topic topic, L2PcInstance activeChar, Forum forum)
{
//
Post p = getGPosttByTopic(topic);
Locale locale = Locale.getDefault();
DateFormat dateFormat = DateFormat.getDateInstance(DateFormat.FULL, locale);
StringBuilder html = new StringBuilder("<html><body><br><br>");
html.append("<table border=0 width=610><tr><td width=10></td><td width=600 align=left>");
html.append("<a action=\"bypass _bbshome\">HOME</a> > <a action=\"bypass _bbsmemo\">Memo Form</a>");
html.append("</td></tr>");
html.append("</table>");
html.append("<img src=\"L2UI.squareblank\" width=\"1\" height=\"10\">");
html.append("<center>");
html.append("<table border=0 cellspacing=0 cellpadding=0 bgcolor=333333>");
html.append("<tr><td height=10></td></tr>");
html.append("<tr>");
html.append("<td fixWIDTH=55 align=right valign=top>&$413; : </td>");
html.append("<td fixWIDTH=380 valign=top>"+topic.getName()+"</td>");
html.append("<td fixwidth=5></td>");
html.append("<td fixwidth=50></td>");
html.append("<td fixWIDTH=120></td>");
html.append("</tr>");
html.append("<tr><td height=10></td></tr>");
html.append("<tr>");
html.append("<td align=right><font color=\"AAAAAA\" >&$417; : </font></td>");
html.append("<td><font color=\"AAAAAA\">"+topic.getOwnerName()+"</font></td>");
html.append("<td></td>");
html.append("<td><font color=\"AAAAAA\">&$418; :</font></td>");
html.append("<td><font color=\"AAAAAA\">"+dateFormat.format(p.getCPost(0).postDate)+"</font></td>");
html.append("</tr>");
html.append("<tr><td height=10></td></tr>");
html.append("</table>");
html.append("<br>");
html.append("<table border=0 cellspacing=0 cellpadding=0>");
html.append("<tr>");
html.append("<td fixwidth=5></td>");
String Mes = p.getCPost(0).postTxt.replace(">",">");
Mes = Mes.replace("<","<");
Mes = Mes.replace("\n","<br1>");
html.append("<td FIXWIDTH=600 align=left>"+ Mes +"</td>");
html.append("<td fixqqwidth=5></td>");
html.append("</tr>");
html.append("</table>");
html.append("<br>");
html.append("<img src=\"L2UI.squareblank\" width=\"1\" height=\"5\">");
html.append("<img src=\"L2UI.squaregray\" width=\"610\" height=\"1\">");
html.append("<img src=\"L2UI.squareblank\" width=\"1\" height=\"5\">");
html.append("<table border=0 cellspacing=0 cellpadding=0 FIXWIDTH=610>");
html.append("<tr>");
html.append("<td width=50>");
html.append("<button value=\"&$422;\" action=\"bypass _bbsmemo\" back=\"l2ui_ch3.smallbutton2_down\" width=65 height=20 fore=\"l2ui_ch3.smallbutton2\">");
html.append("</td>");
html.append("<td width=560 align=right><table border=0 cellspacing=0><tr>");
html.append("<td FIXWIDTH=300></td><td><button value = \"&$424;\" action=\"bypass _bbsposts;edit;"+ forum.getID() +";"+ topic.getID() +";0\" back=\"l2ui_ch3.smallbutton2_down\" width=65 height=20 fore=\"l2ui_ch3.smallbutton2\" ></td> ");
html.append("<td><button value = \"&$425;\" action=\"bypass _bbstopics;del;"+forum.getID()+";"+ topic.getID() +"\" back=\"l2ui_ch3.smallbutton2_down\" width=65 height=20 fore=\"l2ui_ch3.smallbutton2\" ></td> ");
html.append("<td><button value = \"&$421;\" action=\"bypass _bbstopics;crea;"+forum.getID()+"\" back=\"l2ui_ch3.smallbutton2_down\" width=65 height=20 fore=\"l2ui_ch3.smallbutton2\" ></td> ");
html.append("</tr></table>");
html.append("</td>");
html.append("</tr>");
html.append("</table>");
html.append("<br>");
html.append("<br>");
html.append("<br></center>");
html.append("</body>");
html.append("</html>");
separateAndSend(html.toString(),activeChar);
}