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

StringdateToString(Time t)
date To String
return String.format("%04d%02d%02d", t.year, t.month + 1,
        t.monthDay);
StringtoISO8601Date(Time date)
Liefert ein Time -Objekt als ISO-8601-String (Form: YYYY-MM-DD).
String month = normalizeDate("" + date.month);
String day = normalizeDate("" + (date.monthDay + 1));
return date.year + "-" + month + "-" + day;
StringformatDisplay(int second)
Format second to display format like 3:20:30
return format(TIME_DISPLAY_FORMAT, second * 1000);
StringformatDateAndTime(int timestamp, String pattern)
Formats a Unix timestamp in something human readable.
long time = timestamp * ONE_SECOND;
Date date = new Date(time);
SimpleDateFormat formattedDate = new SimpleDateFormat(pattern,
        Locale.getDefault());
return formattedDate.format(date);
StringformatDate(String mounthStr)
format Date
return mounthStr.substring(2, 4) + "/" + mounthStr.substring(4, 6)
        + "/" + mounthStr.substring(6, 8) + " "
        + mounthStr.substring(8, 10) + ":"
        + mounthStr.substring(10, 12);
StringdateTimeFormat(String dateTime)
date Time Format
StringBuilder sb = new StringBuilder();
try {
    if (isEmpty(dateTime)) {
        return null;
    String[] dateAndTime = dateTime.split(" ");
    if (dateAndTime.length > 0) {
        for (String str : dateAndTime) {
...
StringdateTimeFormat(String dateTime)
date Time Format
StringBuilder sb = new StringBuilder();
try {
    if (isEmpty(dateTime)) {
        return null;
    String[] dateAndTime = dateTime.split(" ");
    if (dateAndTime.length > 0) {
        for (String str : dateAndTime) {
...
StringformatDateTime(String date, String format)
format Date Time
return convertDateTime(convertDateTime(date, DEFAULT_FORMAT_DATE),
        format);
StringformatTime(long time)
format Time
Time t = new Time();
t.set(time);
return t.format("%d.%m.%Y %H:%M:%S");
longconvertDateTime(String date, String format)
convert Date Time
try {
    if (format == null) {
        format = DEFAULT_FORMAT_DATE;
    SimpleDateFormat simpleDateFormat = new SimpleDateFormat(format);
    return simpleDateFormat.parse(date).getTime();
} catch (ParseException e) {
    e.printStackTrace();
...