Using the Date Class - Java Date Time

Java examples for Date Time:Legacy Date

Description

Using the Date Class

Demo Code

import java.util.Date;    

public class Main {
  public static void main (String[] args) {
    // Create a new Date object
    Date currentDate = new Date();    
    System.out.println("Current date: " + currentDate);
    //from   ww w  .  ja  v  a 2  s . co  m
    // Get the milliseconds value of the current date
    long millis = currentDate.getTime();
    System.out.println("Current datetime in millis: " + millis);    }
}

Result


Related Tutorials