Android Utililty Methods Time Format

List of utility methods to do Time Format

Description

The list of methods to do Time Format are organized into topic(s).

Method

StringgetTimeStr(long time)
get Time Str
return dateFormater.format(new Date(time));
StringgetTimeString(Date utcDate)
get Time String
if (utcDate.getTime() == 0) {
    return "";
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm",
        Locale.CHINA);
return sdf.format(utcDate.getTime());
StringgetTimeString(String dateString)
get user friendly data string, a combination of getCalenderFromDateString and getUserFriendlyTime
return getUserFriendlyTime(getCalenderFromDateString(dateString));
StringgetTimeString(String utcTimeString)
get Time String
try {
    SimpleDateFormat sdf = new SimpleDateFormat(
            "yyyy-MM-dd'T'HH:mm:ss.SSS'Z'", Locale.US);
    sdf.setTimeZone(TimeZone.getTimeZone("UTC"));
    Date date = sdf.parse(utcTimeString);
    sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss", Locale.CHINA);
    return sdf.format(date.getTime());
} catch (ParseException e) {
...
StringdateTimeToXSDate(Date date)
* Convert DateTime to XML Schema date.
String format = "yyyy-MM-dd'Z'";
DateFormat utcFormatter = new SimpleDateFormat(format);
return utcFormatter.format(date);
StringdateTimeToXSDateTime(Date date)
* Dates the DateTime into an XML schema date time.
String format = "yyyy-MM-dd'T'HH:mm:ss'Z'";
DateFormat utcFormatter = new SimpleDateFormat(format);
return utcFormatter.format(date);