convert Full Date To Milli Seconds - Java java.util

Java examples for java.util:Millisecond

Description

convert Full Date To Milli Seconds

Demo Code


//package com.java2s;

import java.text.ParseException;
import java.text.SimpleDateFormat;

import java.util.Date;
import java.util.TimeZone;

public class Main {
    public static TimeZone timezone = TimeZone.getTimeZone("GMT+0");

    public static long convertFullDateToMilliSeconds(String Date) {
        // Create a DateFormatter object for displaying date in specified format.
        long Time = 0;
        SimpleDateFormat format = new SimpleDateFormat(
                "MM/dd/yyyy HH:mm:ss");
        format.setTimeZone(timezone);//w  ww  . ja  v a  2  s. c  o m

        try {

            Date date = format.parse(Date);
            // Earliest full hour before the start event
            Time = date.getTime();

        } catch (ParseException e) {
            System.err.println("Cannot convert " + Date
                    + " to millisecond.");
        }

        return Time;
    }
}

Related Tutorials