Android Utililty Methods Long to Date Convert

List of utility methods to do Long to Date Convert

Description

The list of methods to do Long to Date Convert are organized into topic(s).

Method

StringgetDate(long timeStamp)
get Date
try {
    SimpleDateFormat sdf = new SimpleDateFormat("MMM dd, yyyy");
    Date netDate = (new Date(timeStamp));
    return sdf.format(netDate);
} catch (Exception ex) {
    return "";
StringgetDateFrom(long timestamp, Context context)
get Date From
if (timestamp <= 0)
    return "";
return DateFormat.getDateFormat(context).format(
        getDateFromLong(timestamp));
DategetDateFromLong(long dateLong)
get Date From Long
if (dateLong == 0) {
    return null;
return new Date(dateLong);
StringgetDateTimeString(long time_milis)
get Date Time String
SimpleDateFormat sdf = getSimpleDateFormat();
return sdf.format(new Date(time_milis));
StringformatTime(long timeInMillis)
format Time
return format(TIME_FORMAT, timeInMillis);
StringformatDate(long timeInMillis)
format Date
return format(DATE_FORMAT, timeInMillis);
StringgetCurrentDate(long time)
get Current Date
DateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd",
        Locale.CHINA);
return dateFormat.format(time);
StringchangeMillisToFormat(long milliseconds, String pattern)
change Millis To Format
Date fecha = new Date(milliseconds);
return changeDateToFormatString(fecha, pattern);
StringconvertLongToDateString(long mills, String format)
convert Long To Date String
SimpleDateFormat sdf = new SimpleDateFormat(format);
String date = sdf.format(mills);
return date;
Stringformat(String pattern, long timeInMillis)
format
final SimpleDateFormat sdf = new SimpleDateFormat(pattern);
return sdf.format(new Date(timeInMillis));