日期和时间格式取决于语言环境 [英] Date and time formatting depending on locale

查看:288
本文介绍了日期和时间格式取决于语言环境的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是新来的Java和Android的发展,这可能是一个愚蠢的问题,但我一直在寻找几天了,不能找到一个解决方案:

I'm new to both Java and Android development so this might be a stupid question, but I've been searching for days now and can't find a solution:

我尝试输出 java.util.Date 根据用户的语言环境。

I try to output a java.util.Date depending on the user's locale.

在搜索上的计算器导致我这样的:

Searching on StackOverflow lead me to this:

java.util.Date date = new Date();
String dateString = DateFormat.getDateFormat(getApplicationContext()).format(date);

此输出:

20/02/2011

在我的法语本地化的手机。差不多就好了。

On my french localized phone. Almost fine.

我如何也输出小时,分钟和秒部分日期,使用用户的语言环境?我一直在寻找在Android文档中也没有找到任何东西。

How can I also output the hours, minutes and seconds parts of the Date, using the user's locale ? I've been looking in the android documentation but couldn't find anything.

非常感谢。

推荐答案

使用 android.text.format.DateFormat.getTimeFormat()

REF:<一href="http://developer.android.com/reference/android/text/format/DateFormat.html">http://developer.android.com/reference/android/text/format/DateFormat.html

这篇关于日期和时间格式取决于语言环境的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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