Java - Write code to convert Time in yyyy-MM-dd HH:mm:ss format to time in millisecond in long value

Requirements

Write code to convert Time in yyyy-MM-dd HH:mm:ss format to time in millisecond in long value

Demo

//package com.book2s;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;

public class Main {
    public static void main(String[] argv) {
        String user_time = "2018-10-12 12:12:12";
        System.out.println(getTime(user_time));
    }/*from   w w w .  j  av  a2s  .c  o  m*/

    public static Long getTime(String user_time) {
        SimpleDateFormat simpleDateFormat = new SimpleDateFormat(
                "yyyy-MM-dd HH:mm:ss");
        Date date;
        try {
            date = simpleDateFormat.parse(user_time);
            Long timeStemp = date.getTime();
            return timeStemp;
        } catch (ParseException e) {
            e.printStackTrace();
        }
        return 0L;
    }
}