import java.text.ParseException; import java.text.SimpleDateFormat; import java.util.Date; public class DateConversion { static long getDateAsLong(String str) throws ParseException{ SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss.SSS"); Date date = format.parse(str); return date.getTime(); } public static void main(String args[]) throws ParseException{ String str = "2013-04-04 04:28:18.000"; long time = getDateAsLong(str); System.out.println(time); } }
Output
1365029898000
No comments:
Post a Comment