Java Calendar getTimeInMillis


Java Calendar getTimeInMillis

package com.codingdict;

import java.util.*;

public class CalendarDemo {

   public static void main(String[] args) throws InterruptedException {

      // create a calendar
      Calendar cal = Calendar.getInstance();

      // print current time in milliseconds
      System.out.println("Current time is : " + cal.getTimeInMillis());

      // add a delay of 2 seconds
      Thread.sleep(2000);

      // create a new calendar
      Calendar cal2 = Calendar.getInstance();

      // print the next time in milliseconds
      long d = cal2.getTimeInMillis();
      System.out.println("Next time is : " + d);
   }
}