Show android date without time
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);
精彩评论