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

intgetDay(long dateTimeMillis)
get Day
SimpleDateFormat format = new SimpleDateFormat("dd");
StringBuilder dateString = new StringBuilder(
        format.format(dateTimeMillis));
return Integer.parseInt(dateString.toString());
intgetDayOfWeek(long timeMillis)
get Day Of Week
Calendar calendar = Calendar.getInstance();
calendar.setTimeInMillis(timeMillis);
return calendar.get(Calendar.DAY_OF_WEEK);
StringgetDefaultDateTimeString(long date, Locale locale)
get Default Date Time String
return getDateTimeString(new Date(date), DateFormat.DEFAULT, locale);
StringgetDefaultDatetime(long milliseconds)
get Default Datetime
Date date = new Date(milliseconds);
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss Z");
return sdf.format(date);
StringgetElapsedDurationSince(long seconds)
get Elapsed Duration Since
String unit = SECOND;
String residueUnit = null;
long currentTimeInSeconds = System.currentTimeMillis() / 1000;
long elapsedTimeInSeconds = currentTimeInSeconds - seconds;
int count = 0;
int residue = 0;
if (elapsedTimeInSeconds > SECONDS_IN_MIN
        && elapsedTimeInSeconds < SECONDS_IN_HOUR) {
...
StringgetFormattedTime(String dateTimeFormat, long timestamp)
Method to get the current date-time in the input format.
Date date = new Date(timestamp);
SimpleDateFormat sdf = new SimpleDateFormat(dateTimeFormat,
        Locale.US);
return sdf.format(date);
StringgetFriendlyDate(Context context, long timestamp)
Returns date from given @param timestamp in friendly format.
if (timestamp < 0)
    return "";
if (sResources == null) {
    sResources = context.getResources();
final long now = System.currentTimeMillis();
final long offset = sTimeZone.getOffset(now);
final long diff = now - offset - timestamp;
...
intgetHour(long dateTimeMillis)
get Hour
SimpleDateFormat format = new SimpleDateFormat("HH");
StringBuilder dateString = new StringBuilder(
        format.format(dateTimeMillis));
return Integer.parseInt(dateString.toString());
intgetHour(long timeMillis)
get Hour
Calendar calendar = Calendar.getInstance();
calendar.setTimeInMillis(timeMillis);
return calendar.get(Calendar.HOUR_OF_DAY);
StringgetHoursAndMinutes(long dateTimeMillis)
get Hours And Minutes
String format = String.format("%%0%dd", 2);
long elapsedTime = dateTimeMillis / 1000;
String minutes = String.format(format, (elapsedTime % 3600) / 60);
String hours = String.format(format, elapsedTime / 3600);
return hours + ":" + minutes;