开发者

Show android date without time

开发者 https://www.devze.com 2023-03-31 03:55 出处:网络
Is there a reliable way I can get the current date without time regardless of locale? If I use .toGMTString() I get it in this format : EEE MMM dd HH:mm:ss z yyyy

Is there a reliable way I can get the current date without time regardless of locale? If I use .toGMTString() I get it in this format : EEE MMM dd HH:mm:ss z yyyy

I need it to work regardless of country so in the UK it would be DD/MM/YYYY but in the us MM/DD/YYYY

I'm sure there must be a really easy way to do this but 开发者_如何学Gocan I find it?!


There is a special helper class for this in android: android.text.format.DateFormat. It has a static public method called getDateFormat() which returns locale aware and user-setttings aware date formatter.

You can use it to format the date only part:

String formattedDate = DateFormat.getDateFormat(mContext).format(new Date());   


Use SimpleDateFormat. Code sample.

SimpleDateFormat sdf = new SimpleDateFormat("E MMM dd yyyy"); 
sdf.format(new Date());

This would return Thu Aug 25 2011 for today's date.


myString = DateFormat.getDateInstance(DateFormat.MEDIUM).format(myDate);
0

精彩评论

暂无评论...
验证码 换一张
取 消