SimpleDateFormat的(字符串模板,区域设置区域)与例如Locale.US的ASCII日期 [英] SimpleDateFormat(String template, Locale locale) with for example Locale.US for ASCII dates

查看:1464
本文介绍了SimpleDateFormat的(字符串模板,区域设置区域)与例如Locale.US的ASCII日期的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

问题:直接使用的SimpleDateFormat没有明确的语言环境 编号:SimpleDateFormat的

Issue: Using SimpleDateFormat directly without an explicit locale Id: SimpleDateFormat

SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");

为什么是要获得本地格式使用getDateInstance(),getDateTimeInstance(),或getTimeInstance(),或使用新的SimpleDateFormat(字符串模板,区域设置区域)与例如Locale.US的ASCII日期的错误在这条线上来了。

Why is the "To get local formatting use getDateInstance(), getDateTimeInstance(), or getTimeInstance(), or use new SimpleDateFormat(String template, Locale locale) with for example Locale.US for ASCII dates" error coming on this line.

<一个href="http://developer.android.com/reference/java/text/SimpleDateFormat.html">http://developer.android.com/reference/java/text/SimpleDateFormat.html

推荐答案

要删除警告只需添加Locale.getDefault()作为第二个参数在实例的日期格式对象。 例如:

To remove the warning just add Locale.getDefault() as the second argument while instantiating the date format object. Eg.

 SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss",
                    java.util.Locale.getDefault());

这篇关于SimpleDateFormat的(字符串模板,区域设置区域)与例如Locale.US的ASCII日期的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆