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

DateGetDate(long milliseconds)
Get Date
return new Date(milliseconds);
longconvToEnglishTime(long dateMsec)
conv To English Time
Time androTime;
androTime = new Time();
androTime.switchTimezone(TimeZone.getDefault().getDisplayName(
        Locale.ENGLISH));
androTime.set(dateMsec);
return androTime.normalize(true);
StringconverTime(long timestamp, String[] timeLabels)
conver Time
long currentSeconds = System.currentTimeMillis() / 1000;
long timeGap = currentSeconds - timestamp;
String timeStr = null;
if (timeGap > 24 * 60 * 60) {
    timeStr = timeGap / (24 * 60 * 60) + timeLabels[0];
} else if (timeGap > 60 * 60) {
    timeStr = timeGap / (60 * 60) + timeLabels[1];
} else if (timeGap > 60) {
...
StringconvertNotNull(Long long1)
convert Not Null
String str = String.valueOf(long1);
if (StringUtils.isEmpty(str) || long1.equals("0")) {
    return "null";
Date date = parseDate(str);
if (date == null) {
    return "null";
} else {
...
StringconvertToDateStamp(long time)
Convert given date to string
OutputFormat: yyyymmdd_hhmm
Calendar cal = Calendar.getInstance();
cal.setTime(new Date(time));
return convertToDateStamp(cal);
StringconvertToTimeStamp(long time)
Convert date to short time string
return convertToTimeStamp(time, true);
StringconvertToTimeStamp(long time, boolean showSeconds)
Convert date to short time string
return convertToTimeStamp(new Date(time), showSeconds);
DatedateFromUnixTimestamp(final long unixTimestamp)
date From Unix Timestamp
final Calendar cal = Calendar.getInstance();
cal.setTimeInMillis(unixTimestamp * 1000);
return cal.getTime();
DatedateFromUtc(long milliseconds)
date From Utc
Calendar cal = new GregorianCalendar(TimeZone.getTimeZone("UTC"));
cal.setTimeInMillis(milliseconds);
return cal.getTime();
StringdateUtil(long date)
date Util
Date d = new Date();
d.setTime(date);
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss",
        java.util.Locale.getDefault());
String str = sdf.format(d);
return str;