Converts time from a long to a string in a format set by the user in the phone's settings.
import android.content.Context;
import android.text.format.DateUtils;
class Main {
/**
* Converts time from a long to a string in a format set by the user in the
* phone's settings.
*
* @param ctx
* context to get access to the conversion methods
* @param secs
* time since 1970, UTC, in seconds
* @return the time since 1970, UTC, as a string (e.g. 2009-10-23 12:25)
*/
public static String timeFromUTCSecs(Context ctx, long secs) {
return DateUtils.formatDateTime(ctx, secs * 1000,
DateUtils.FORMAT_SHOW_TIME | DateUtils.FORMAT_SHOW_DATE
| DateUtils.FORMAT_NUMERIC_DATE);
}
}
Related examples in the same category