Create Date object

ConstructorSummary
Date()Creates a Date object and initializes it with the time at which it was allocated.
Date(long date)Creates a Date object and initializes it to represent the specified number of milliseconds since the standard base time known as "the epoch", namely January 1, 1970, 00:00:00 GMT.

import java.util.Date;

public class Main{
  public static void main(String args[]) {
    Date date = new Date();

    System.out.println(date);

    long msec = date.getTime();
    System.out.println("Milliseconds since Jan. 1, 1970 GMT=" + msec);
  }
}

The output:


Sat Oct 30 09:10:12 PDT 2010
Milliseconds since Jan. 1, 1970 GMT=1288455012000

Create java Date from specific time


import java.util.Date;

import java.util.Date;

public class Main {
  public static void main(String[] args) {
    Date d = new Date(365L * 24L * 60L * 60L * 1000L+99999999L);
    System.out.println(d);
  }
}

The output:


Fri Jan 01 19:46:39 PST 1971
java2s.com  | Contact Us | Privacy Policy
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.