Android Utililty Methods Date to Long Convert

List of utility methods to do Date to Long Convert

Description

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

Method

LongparseDateToLong(String dateString)
parse Date To Long, "yyyy-MM-dd HH:mm"
if (StringUtils.isEmpty(dateString) || dateString.equals("0")) {
    return 0L;
Date date = parseDate(dateString);
if (date == null) {
    return null;
} else {
    return date.getTime();
...
longparseDateToLong2(String dateString)
parse Date To Long, "yyyy-MM-dd"
SimpleDateFormat sdf = new SimpleDateFormat(FORMAT_DATE_YYYY_MM_DD);
Date date;
try {
    date = sdf.parse(dateString);
    return date.getTime();
} catch (ParseException e) {
    e.printStackTrace();
return 0;
StringparseDateToLongString(String dateString)
parse Date To Long String, "yyyy-MM-dd HH:mm"
if (StringUtils.isEmpty(dateString)) {
    return "";
Long dateLong = parseDateToLong(dateString);
if (dateLong == null) {
    return null;
} else {
    return String.valueOf(dateLong);
...
longgeLongFromString(final String date)
ge Long From String
final Calendar calendar = getCalendarFromString(date);
return calendar.getTimeInMillis();
longgetTime(String dateString)
get Time
SimpleDateFormat formatter = new SimpleDateFormat(
        "yyyy-MM-dd HH:mm:ss");
try {
    Date date = formatter.parse(dateString);
    return date.getTime();
} catch (ParseException e) {
    e.printStackTrace();
return SystemClock.elapsedRealtime();
longdosToJavaTime(long dosTime)
Converts DOS time to Java time (number of milliseconds since epoch).
Calendar cal = Calendar.getInstance();
cal.set(Calendar.YEAR, (int) ((dosTime >> 25) & 0x7f) + 1980);
cal.set(Calendar.MONTH, (int) ((dosTime >> 21) & 0x0f) - 1);
cal.set(Calendar.DATE, (int) (dosTime >> 16) & 0x1f);
cal.set(Calendar.HOUR_OF_DAY, (int) (dosTime >> 11) & 0x1f);
cal.set(Calendar.MINUTE, (int) (dosTime >> 5) & 0x3f);
cal.set(Calendar.SECOND, (int) (dosTime << 1) & 0x3e);
return cal.getTime().getTime();
...
longdosToJavaTme(int dosTime)
Converts time in dos format to Java format
int sec = 2 * (dosTime & 0x1f);
int min = (dosTime >> 5) & 0x3f;
int hrs = (dosTime >> 11) & 0x1f;
int day = (dosTime >> 16) & 0x1f;
int mon = ((dosTime >> 21) & 0xf) - 1;
int year = ((dosTime >> 25) & 0x7f) + 1980;
Calendar cal = Calendar.getInstance();
cal.set(year, mon, day, hrs, min, sec);
...
longgetDateLong(Date date)
get Date Long
if (date == null) {
    return 0;
} else {
    return date.getTime();