I'm using the Location class and the getTime() method to get the current time in Android. Then I'm sending that Long number to some other device. That device receives the Long number and should display the data in a message box, but I don't know how to convert it into DD:MM:YY and time of the day (or anything readable by a human, actually). How do I do this? I can't use the current format, it has to be something that the average user can read.
Thank you!
Assuming you don't want to use Joda Time (might be a bit big for an Android app) you should probably use a DateFormat such as SimpleDateFormat:
// See notes below
DateFormat format = new SimpleDateFormat("dd/MM/yyyy HH:mm:ss");
Date date = new Date(location.getTime());
String formatted = format.format(date);
There are cultural issues you should consider though:
DateFormat.getDateTimeInstance()DateFormat you create, but perhaps something else...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