I am using Date.toLocaleString() in my app to get a string representation of the date - I only want the date (ie. Apr 5, 2012) without the time elements, is this possible?
However I achieve this I need it to be multi language so '5/4/2012' is no good as US dates are MM/DD/YYYY rather than DD/MM/YYYY for the UK.
Thanks
As mentioned in the documentation, this method is deprecated. Instead, you should use a DateFormat (such as SimpleDateFormat or the built-in ones) which makes it easy to specify date patterns.
For example:
// You can specify styles if you want
DateFormat format = DateFormat.getDateInstance();
// Set time zone information if you want.
Date date = ...;
String text = format.format(date);
I would like to answer your question in the comment by quoting the Android documentation of DateFormat class:
Most callers should avoid supplying their own format strings to this class' format methods, and rely on the correctly localized ones supplied by the system. This class' factory methods return appropriately-localized DateFormat instances, suitable for both formatting and parsing dates. For the canonical documentation of format strings, see SimpleDateFormat.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With