In Java, you can use following methods to get time in milliseconds

  1. Date class – getTime() method
  2. Calendar class – getTimeInMillis() method
package com.mkyong.test;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
public class TimeMilisecond {
  public static void main(String[] argv) throws ParseException {
	SimpleDateFormat sdf = new SimpleDateFormat("dd-M-yyyy hh:mm:ss");
	String dateInString = "22-01-2015 10:20:56";
	Date date = sdf.parse(dateInString);
	System.out.println("Date - Time in milliseconds : " + date.getTime());
	Calendar calendar = Calendar.getInstance();
	System.out.println("Calender - Time in milliseconds : " + calendar.getTimeInMillis());


22-01-2015 10:20:56
Date - Time in milliseconds : 1421893256000
Calender - Time in milliseconds : 1421893256000
Tags :
Founder of, love Java and open source stuff. Follow him on Twitter, or befriend him on Facebook or Google Plus. If you like my tutorials, consider make a donation to these charities.
My website is hosted by Liquid Web, I really like their fast and helpful support, it saved me a lot of time. Furthermore, their servers are extremely reliable, fast and stable, I don't remember when was the last time we had server downtime. Btw, they're offering $100 Coupon now, if you are sourcing for great hosting provider, go grab it.

Related Posts

Popular Posts