Android Date to Long Convert parseDateToLong(String dateString)

Here you can find the source of parseDateToLong(String dateString)


parse Date To Long, "yyyy-MM-dd HH:mm"


public static Long parseDateToLong(String dateString) 

Method Source Code

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
import android.annotation.SuppressLint;

public class Main{
    private static final String FORMAT_DATE_AND_TIME_YYYY_MM_DD_HH_MM = "yyyy-MM-dd HH:mm";
    public static Long parseDateToLong(String dateString) {
        if (StringUtils.isEmpty(dateString) || dateString.equals("0")) {
            return 0L;
        }/*from   w  ww. j a  v a 2  s . com*/
        Date date = parseDate(dateString);
        if (date == null) {
            return null;
        } else {
            return date.getTime();
    public static Date parseDate(String dateString) {
        SimpleDateFormat sdf = new SimpleDateFormat(
        try {
            return sdf.parse(dateString);
        } catch (Exception e) {
            return null;


  1. parseDateToLong2(String dateString)
  2. parseDateToLongString(String dateString)
  3. geLongFromString(final String date)
  4. getTime(String dateString)