Link to home
Start Free TrialLog in
Avatar of rkneal
rkneal

asked on

Convert String MM/dd/yyyy hh:mm:ss to Milliseconds in Java

I need to know if there is a way to convert a string in MM/dd/yyyy hh:mm:ss format to its equivalent in milliseconds (Epoch time) in Java?  I have a string in this format that I need to convert to milliseconds so I can send the converted value through my program that requires the time to be in this format.  Any help would be appreciated.  
Avatar of Ajay-Singh
Ajay-Singh

You can use SimpleDateFormat to parse and get the epoach

String text = ... // Date text
Date date = new SimpleDateFormat("MM/dd/yyyy hh:mm:ss").parse(text);
long epoach = date.getTime();
Use the class SimpleDateFormat.
String date = "......";
SimpleDateFormat format = new SimpleDateFormat("MM/dd/yyyy hh:mm:ss");
Date d = format.parse(date);
long time = d.getTime();

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of rkneal
rkneal

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial