Android Date to Milliseconds Convert getTimeInMillis(String date)

Here you can find the source of getTimeInMillis(String date)

Description

get Time In Millis

Declaration

@SuppressLint("SimpleDateFormat")
public static long getTimeInMillis(String date) 

Method Source Code

//package com.java2s;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
import android.annotation.SuppressLint;

public class Main {
    public static Calendar calendar = Calendar.getInstance();

    @SuppressLint("SimpleDateFormat")
    public static long getTimeInMillis(String date) {
        Date currentDate;/*from w  ww  .  ja  va2s . c  om*/
        try {
            String format = "HH:mm";
            if (date.contains("-")) {
                format = "yyyy-MM-dd HH:mm:ss";
            }
            SimpleDateFormat dateForamt = new SimpleDateFormat(format);
            currentDate = dateForamt.parse(date);
        } catch (ParseException e) {
            e.printStackTrace();

            currentDate = new Date();
        }
        calendar.setTime(currentDate);
        return calendar.getTimeInMillis();
    }
}

Related

  1. millisecondOf(int year, int month, int day)
  2. millisecondOf(int year, int month, int day, int hour, int minute)