下面列出了java.text.SimpleDateFormat#applyLocalizedPattern ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
private static String getFormattedFullDate(Date date)
{
SimpleDateFormat dateFormat = (SimpleDateFormat) SimpleDateFormat.getDateInstance(SimpleDateFormat.FULL);
String pattern = dateFormat.toLocalizedPattern();
pattern = pattern.replace("E", "");
pattern = pattern.replace(",", "");
pattern = pattern.replace(" ", " ");
pattern = pattern.trim();
dateFormat.applyLocalizedPattern(pattern);
return dateFormat.format(date);
}
/**
* (non-API) Method initializeColumnHeaders. Called internally when the column
* header text needs to be updated.
*
* @param columns
* A LinkedList of CLabels representing the column objects
*/
protected void refreshColumnHeaders(LinkedList<CLabel> columns) {
Date startDate = getStartDate();
GregorianCalendar gc = new GregorianCalendar();
gc.setTime(startDate);
SimpleDateFormat formatter = new SimpleDateFormat("EE, MMM d");
formatter.applyLocalizedPattern(formatter.toLocalizedPattern());
for (Iterator<CLabel> iter = columns.iterator(); iter.hasNext();) {
CLabel headerLabel = iter.next();
headerLabel.setText(formatter.format(gc.getTime()));
gc.add(Calendar.DATE, 1);
}
}
private static SimpleDateFormat getDateFormat()
{
SimpleDateFormat dateFormat = (SimpleDateFormat) SimpleDateFormat.getDateInstance(SimpleDateFormat.FULL);
String pattern = dateFormat.toLocalizedPattern();
pattern = pattern.replace("y", "");
pattern = pattern.replace("E", "");
pattern = pattern.replace(",", "");
pattern = pattern.replace(" ", " ");
pattern = pattern.trim();
dateFormat.applyLocalizedPattern(pattern);
return dateFormat;
}
/**
* Creates an object based on this description.
*
* @return The object.
*/
public Object createObject() {
final SimpleDateFormat format = (SimpleDateFormat) super.createObject();
if (getParameter("pattern") != null) {
format.applyPattern((String) getParameter("pattern"));
}
if (getParameter("localizedPattern") != null) {
format.applyLocalizedPattern((String) getParameter("localizedPattern"));
}
return format;
}
public static String formatLocale(Date date, String format) {
String result = "";
if (date != null) {
SimpleDateFormat dateFormat = new SimpleDateFormat(format);
dateFormat.applyLocalizedPattern(format);
try {
result = dateFormat.format(date);
} catch (Exception e) {
e.printStackTrace();
return result;
}
}
return result;
}
@Override
protected Object parse(Object value, String pattern) throws ParseException
{
SimpleDateFormat formatter = getFormatter(pattern, locale);
if (pattern != null)
{
if (locPattern) {
formatter.applyLocalizedPattern(pattern);
}
else {
formatter.applyPattern(pattern);
}
}
return formatter.parse((String) value);
}
@NonNull
private String getMonthAndYearString() {
Locale locale = Locale.getDefault();
String pattern = "MMMM yyyy";
if(Build.VERSION.SDK_INT < 18) pattern = getContext().getResources().getString(R.string.mdtp_date_v1_monthyear);
else pattern = DateFormat.getBestDateTimePattern(locale, pattern);
SimpleDateFormat formatter = new SimpleDateFormat(pattern, locale);
formatter.applyLocalizedPattern(pattern);
mStringBuilder.setLength(0);
return formatter.format(mCalendar.getTime());
}
public static void main(String args[]) {
SimpleDateFormat df = (SimpleDateFormat)
DateFormat.getDateInstance(DateFormat.DEFAULT, Locale.GERMAN);
df.applyLocalizedPattern("tt.MM.uuuu");
System.out.println(df.format(new Date()));
}
public static void main(String args[]) {
SimpleDateFormat df = (SimpleDateFormat)
DateFormat.getDateInstance(DateFormat.DEFAULT, Locale.GERMAN);
df.applyLocalizedPattern("tt.MM.uuuu");
System.out.println(df.format(new Date()));
}
public static void main(String args[]) {
SimpleDateFormat df = (SimpleDateFormat)
DateFormat.getDateInstance(DateFormat.DEFAULT, Locale.GERMAN);
df.applyLocalizedPattern("tt.MM.uuuu");
System.out.println(df.format(new Date()));
}
public static void main(String args[]) {
SimpleDateFormat df = (SimpleDateFormat)
DateFormat.getDateInstance(DateFormat.DEFAULT, Locale.GERMAN);
df.applyLocalizedPattern("tt.MM.uuuu");
System.out.println(df.format(new Date()));
}
public static void main(String args[]) {
SimpleDateFormat df = (SimpleDateFormat)
DateFormat.getDateInstance(DateFormat.DEFAULT, Locale.GERMAN);
df.applyLocalizedPattern("tt.MM.uuuu");
System.out.println(df.format(new Date()));
}
public static void main(String args[]) {
SimpleDateFormat df = (SimpleDateFormat)
DateFormat.getDateInstance(DateFormat.DEFAULT, Locale.GERMAN);
df.applyLocalizedPattern("tt.MM.uuuu");
System.out.println(df.format(new Date()));
}
public static void main(String args[]) {
SimpleDateFormat df = (SimpleDateFormat)
DateFormat.getDateInstance(DateFormat.DEFAULT, Locale.GERMAN);
df.applyLocalizedPattern("tt.MM.uuuu");
System.out.println(df.format(new Date()));
}
public static void main(String args[]) {
SimpleDateFormat df = (SimpleDateFormat)
DateFormat.getDateInstance(DateFormat.DEFAULT, Locale.GERMAN);
df.applyLocalizedPattern("tt.MM.uuuu");
System.out.println(df.format(new Date()));
}
public static void main(String args[]) {
SimpleDateFormat df = (SimpleDateFormat)
DateFormat.getDateInstance(DateFormat.DEFAULT, Locale.GERMAN);
df.applyLocalizedPattern("tt.MM.uuuu");
System.out.println(df.format(new Date()));
}
public static void main(String args[]) {
SimpleDateFormat df = (SimpleDateFormat)
DateFormat.getDateInstance(DateFormat.DEFAULT, Locale.GERMAN);
df.applyLocalizedPattern("tt.MM.uuuu");
System.out.println(df.format(new Date()));
}
public static void main(String args[]) {
SimpleDateFormat df = (SimpleDateFormat)
DateFormat.getDateInstance(DateFormat.DEFAULT, Locale.GERMAN);
df.applyLocalizedPattern("tt.MM.uuuu");
System.out.println(df.format(new Date()));
}
public static void main(String args[]) {
SimpleDateFormat df = (SimpleDateFormat)
DateFormat.getDateInstance(DateFormat.DEFAULT, Locale.GERMAN);
df.applyLocalizedPattern("tt.MM.uuuu");
System.out.println(df.format(new Date()));
}
public static void main(String args[]) {
SimpleDateFormat df = (SimpleDateFormat)
DateFormat.getDateInstance(DateFormat.DEFAULT, Locale.GERMAN);
df.applyLocalizedPattern("tt.MM.uuuu");
System.out.println(df.format(new Date()));
}