本文整理了Java中java.util.Locale.getDefault()
方法的一些代码示例,展示了Locale.getDefault()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Locale.getDefault()
方法的具体详情如下:
包路径:java.util.Locale
类名称:Locale
方法名:getDefault
[英]Returns the user's preferred locale. This may have been overridden for this process with #setDefault.
Since the user's locale changes dynamically, avoid caching this value. Instead, use this method to look it up for each use.
[中]返回用户的首选区域设置。此进程可能已使用#setDefault覆盖此选项。
由于用户的区域设置会动态更改,请避免缓存此值。相反,使用此方法查找每次使用。
代码示例来源:origin: stackoverflow.com
SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss",
java.util.Locale.getDefault());
代码示例来源:origin: wildfly/wildfly
private static ResourceBundle getResourceBundle(Locale locale) {
if (locale == null) {
locale = Locale.getDefault();
}
return ResourceBundle.getBundle(RESOURCE_NAME, locale);
}
}
代码示例来源:origin: kaushikgopal/RxJava-Android-Samples
private String _getCurrentTimestamp() {
return new SimpleDateFormat("k:m:s:S a", Locale.getDefault()).format(new Date());
}
}
代码示例来源:origin: stackoverflow.com
private String getDateTime() {
SimpleDateFormat dateFormat = new SimpleDateFormat(
"yyyy-MM-dd HH:mm:ss", Locale.getDefault());
Date date = new Date();
return dateFormat.format(date);
}
ContentValues values = new ContentValues();
values.put('username', 'ravitamada');
values.put('created_at', getDateTime());
// insert the row
long id = db.insert('users', null, values);
代码示例来源:origin: stackoverflow.com
Calendar calendar = Calendar.getInstance(TimeZone.getTimeZone("GMT"),
Locale.getDefault());
Date currentLocalTime = calendar.getTime();
DateFormat date = new SimpleDateFormat("Z");
String localTime = date.format(currentLocalTime);
代码示例来源:origin: xalan/xalan
throws MissingResourceException
Locale locale = Locale.getDefault();
return (ListResourceBundle)ResourceBundle.getBundle(className, locale);
return (ListResourceBundle)ResourceBundle.getBundle(
className, new Locale("en", "US"));
throw new MissingResourceException(
"Could not load any resource bundles." + className, className, "");
代码示例来源:origin: TeamNewPipe/NewPipe
public static Locale getPreferredLocale(Context context) {
SharedPreferences sp = PreferenceManager.getDefaultSharedPreferences(context);
String languageCode = sp.getString(context.getString(R.string.content_language_key),
context.getString(R.string.default_language_value));
try {
if (languageCode.length() == 2) {
return new Locale(languageCode);
} else if (languageCode.contains("_")) {
String country = languageCode.substring(languageCode.indexOf("_"), languageCode.length());
return new Locale(languageCode.substring(0, 2), country);
}
} catch (Exception ignored) {
}
return Locale.getDefault();
}
代码示例来源:origin: RipMeApp/ripme
/**
* Gets the ResourceBundle AKA language package.
* Used for choosing the language of the UI.
*
* @return Returns the default resource bundle using the language specified in the config file.
*/
public static ResourceBundle getResourceBundle(String langSelect) {
if (langSelect == null) {
if (!getConfigString("lang", "").equals("")) {
String[] langCode = getConfigString("lang", "").split("_");
LOGGER.info("Setting locale to " + getConfigString("lang", ""));
return ResourceBundle.getBundle("LabelsBundle", new Locale(langCode[0], langCode[1]), new UTF8Control());
}
} else {
String[] langCode = langSelect.split("_");
LOGGER.info("Setting locale to " + langSelect);
return ResourceBundle.getBundle("LabelsBundle", new Locale(langCode[0], langCode[1]), new UTF8Control());
}
try {
LOGGER.info("Setting locale to default");
return ResourceBundle.getBundle("LabelsBundle", Locale.getDefault(), new UTF8Control());
} catch (MissingResourceException e) {
LOGGER.info("Setting locale to root");
return ResourceBundle.getBundle("LabelsBundle", Locale.ROOT);
}
}
代码示例来源:origin: robovm/robovm
if (cl != null) {
try {
return ResourceBundle.getBundle(resourceBundleName, Locale.getDefault(), cl);
} catch (MissingResourceException ignored) {
if (cl != null) {
try {
return ResourceBundle.getBundle(resourceBundleName, Locale.getDefault(), cl);
} catch (MissingResourceException ignored) {
throw new MissingResourceException("Failed to load the specified resource bundle \"" +
resourceBundleName + "\"", resourceBundleName, null);
代码示例来源:origin: knowm/XChange
public Date getTimestamp() {
try {
// Parse the timestamp into a Date object
return new SimpleDateFormat("EEE, dd MMM yyyy HH:mm:ss Z", Locale.getDefault())
.parse(timestamp);
} catch (IllegalArgumentException | ParseException e) {
// Return current Date
return new Date();
}
}
代码示例来源:origin: stackoverflow.com
String timeStamp = new SimpleDateFormat("yyyyMMdd_HHmmss",
Locale.getDefault()).format(new Date());
try {
mediaFile = File.createTempFile(
代码示例来源:origin: guardianproject/haven
/**
* Get a user friendly date and time representation from a given {@link Date}.
* The default {@link Locale} is used.
*
* @param date concerned {@link Date} instance
* @return a string of the format "yyyy-MM-dd_HH-mm-ss.SSS" for the corresponding date
*/
public static String getDateTime(Date date) {
return new SimpleDateFormat(DATE_TIME_PATTERN, Locale.getDefault()).format(date);
}
}
代码示例来源:origin: stackoverflow.com
SimpleDateFormat dateFormat = new SimpleDateFormat( "LLLL", Locale.getDefault() );
dateFormat.format( date );
代码示例来源:origin: robovm/robovm
Locale locale = Locale.getDefault();
String suffix = getResourceSuffix(locale);
return (XSLTErrorResources) ResourceBundle.getBundle(className
+ suffix, locale);
return (XSLTErrorResources) ResourceBundle.getBundle(className,
new Locale("en", "US"));
throw new MissingResourceException(
"Could not load any resource bundles.", className, "");
代码示例来源:origin: stanfordnlp/CoreNLP
public CustomDateFormatExtractor(String timePattern, String localeString) {
Locale locale = (localeString != null)? new Locale(localeString): Locale.getDefault();
this.timePattern = timePattern;
builder = new FormatterBuilder();
builder.locale = locale;
parsePatternTo(builder, timePattern);
textPattern = builder.toTextPattern();
}
代码示例来源:origin: org.postgresql/postgresql
private GT() {
try {
//JCP! if mvn.project.property.postgresql.jdbc.spec < "JDBC4.1"
//JCP> _bundle = ResourceBundle.getBundle("org.postgresql.translation.messages");
//JCP! else
_bundle = ResourceBundle.getBundle("org.postgresql.translation.messages", Locale.getDefault(Locale.Category.DISPLAY));
//JCP! endif
} catch (MissingResourceException mre) {
// translation files have not been installed
_bundle = null;
}
}
代码示例来源:origin: Justson/AgentWeb
static File createImageFile(Context context) {
File mFile = null;
try {
String timeStamp =
new SimpleDateFormat("yyyyMMddHHmmss", Locale.getDefault()).format(new Date());
String imageName = String.format("aw_%s.jpg", timeStamp);
mFile = createFileByName(context, imageName, true);
} catch (Throwable e) {
}
return mFile;
}
代码示例来源:origin: javamelody/javamelody
final DateFormat dateFormat = new SimpleDateFormat("yyyyMMdd_HHmmss",
Locale.getDefault());
final File heapDumpFile = new File(path, "heapdump-" + Parameters.getHostName() + '-'
+ PID.getPID() + '-' + dateFormat.format(new Date()) + ".hprof");
if (heapDumpFile.exists()) {
try {
代码示例来源:origin: DozerMapper/dozer
private DateFormat determineDateFormat() {
return dfStr == null ? null : new SimpleDateFormat(dfStr, Locale.getDefault());
}
}
代码示例来源:origin: stackoverflow.com
public static String formateDateFromstring(String inputFormat, String outputFormat, String inputDate){
Date parsed = null;
String outputDate = "";
SimpleDateFormat df_input = new SimpleDateFormat(inputFormat, java.util.Locale.getDefault());
SimpleDateFormat df_output = new SimpleDateFormat(outputFormat, java.util.Locale.getDefault());
try {
parsed = df_input.parse(inputDate);
outputDate = df_output.format(parsed);
} catch (ParseException e) {
LOGE(TAG, "ParseException - dateFormat");
}
return outputDate;
}
内容来源于网络,如有侵权,请联系作者删除!