Reputation: 24194
How to get the number of milliseconds from October 15th 2011 1:52:34 P.M.
I can get the number of milliseconds from the current time.
Date date = new Date();
long currentTime = date.getTime();
System.out.println("Current time in long: " + currentTime);
Upvotes: 2
Views: 2225
Reputation: 8293
long now = System.currentTimeMillis(); // Simpler way to get current time
Date date = new SimpleDateFormat("dd yyyy h:mm:ss a").parse("15 2011 1:52:34 PM");
long timeElapsed = now - date.getTime(); // Here's your number of ms
Upvotes: 7
Reputation: 1480
Use java.util.Calendar and fill it with your date information. Then use java.util.Calendar.getTimeInMillis()
to get the number of milliseconds since epoch.
Upvotes: 0
Reputation: 69002
You could use SimpleDateFormat to parse an arbitrariy date and get the difference in ms.
Upvotes: 0
Reputation: 2154
import java.util.Calendar;
import java.util.Date;
public class TimeMilisecond {
public static void main(String[] argv) {
long lDateTime = new Date().getTime();
System.out.println("Date() - Time in milliseconds: " + lDateTime);
Calendar lCDateTime = Calendar.getInstance();
System.out.println("Calender - Time in milliseconds :" + lCDateTime.getTimeInMillis());
}
}
Upvotes: 0
Reputation: 4324
Use the Calendar API. Then set the month, date and the time you want (October 15, 2011). To get you started look into this:
Calendar c = Calendar.getInstance();
Hope this helps!
Upvotes: 2