带格式和语言环境的日期
Date with format and locale
我正在尝试使用此模式获取日期 - "dd/MM/yyyy"。
到目前为止,我已经使用 SimpleDateFormat 来实现它,但现在我还需要在我的应用程序中支持中文,但它没有给我我需要的结果。
我试图让它看起来像注意语言环境的模式:
英语:16/05/2016
中文: 2016年05月16日
我尝试了不同的选择 -
android.text.format.DateUtils.formatDateTime
android.text.format.DateFormat.getDateFormat
但是得不到我想要的结果。
谢谢
如果您想要特定的模式,您必须测试语言环境并应用您想要的格式。
对于您的英文和中文格式:
CharSequence englishDate = DateFormat.format("dd/MM/yyyy", date);
CharSequence chineseDate = DateFormat.format("yyyy年MM月dd日", date);
结果是:
25/05/2016
和 2016年05月25日
我正在尝试使用此模式获取日期 - "dd/MM/yyyy"。 到目前为止,我已经使用 SimpleDateFormat 来实现它,但现在我还需要在我的应用程序中支持中文,但它没有给我我需要的结果。
我试图让它看起来像注意语言环境的模式: 英语:16/05/2016 中文: 2016年05月16日
我尝试了不同的选择 - android.text.format.DateUtils.formatDateTime android.text.format.DateFormat.getDateFormat
但是得不到我想要的结果。 谢谢
如果您想要特定的模式,您必须测试语言环境并应用您想要的格式。
对于您的英文和中文格式:
CharSequence englishDate = DateFormat.format("dd/MM/yyyy", date);
CharSequence chineseDate = DateFormat.format("yyyy年MM月dd日", date);
结果是:
25/05/2016
和 2016年05月25日