
how do i convert String date="Aug 31, 2012 19:23:17.907339000 IST" to long value

Here is a code that converts string date to long.
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.Date;
public class ConvertStringDateToLong {
public static void main(String[] args) throws Exception {
String today = "Aug 31, 2012 19:23:17.907339000 IST";
DateFormat formatter = new SimpleDateFormat("MMM dd, yyyy HH:mm:ss.S z");
Date date = formatter.parse(today);
long dateInLong = date.getTime();
System.out.println("date = " + date);
System.out.println("dateInLong = " + dateInLong);
}
}

Thank you for your post. The output dateInLong gives millisecond but i want nanosecond long value for the exact date "Aug 31, 2012 19:23:17.907339000 IST" how can i do..?
If you are facing any programming issue, such as compilation errors or not able to find the code you are looking for.
Ask your questions, our development team will try to give answers to your questions.