日期和时间格式取决于区域设置 [英] Date and time formatting depending on locale

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

问题描述

我很开心Java和Android开发,所以这可能是一个愚蠢的问题,但是我一直在搜索几天,找不到解决方案:



我尝试根据用户的区域设置输出一个 java.util.Date



在StackOverflow上搜索引导我:

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

输出:

  20/02/2011 

在我的法语本地化手机上。几乎可以。



我还可以输出 Date 小时,分和秒部分 $ c>,使用用户的区域设置?我一直在寻找Android文档,但找不到任何东西。



非常感谢。

解决方案

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



ref : http://developer.android.com/reference/android/text/ format / DateFormat.html


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:

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);

This outputs:

20/02/2011

On my french localized phone. Almost fine.

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.

Many thanks.

解决方案

Use android.text.format.DateFormat.getTimeFormat()

ref: http://developer.android.com/reference/android/text/format/DateFormat.html

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

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