Example usage for java.util Date getTime

List of usage examples for java.util Date getTime

Introduction

In this page you can find the example usage for java.util Date getTime.

Prototype

public long getTime() 

Source Link

Document

Returns the number of milliseconds since January 1, 1970, 00:00:00 GMT represented by this Date object.

Usage

From source file:Main.java

public static void main(String[] args) {

    Date date = new Date();
    long diff = date.getTime();

    System.out.println(diff);// w ww  .j  a  va  2 s.c om

}

From source file:Main.java

public static void main(String[] av) {
    Date d1 = new GregorianCalendar(2000, 11, 31, 23, 59).getTime();

    Date today = new Date();

    long diff = today.getTime() - d1.getTime();

    System.out.println(//from  ww  w  .j a  v a  2s. c  o  m
            "The 21st century (up to " + today + ") is " + (diff / (1000 * 60 * 60 * 24)) + " days old.");
}

From source file:MainClass.java

public static void main(String[] a) throws Exception {
    Date d1 = new GregorianCalendar(2000, 11, 31, 23, 59).getTime();

    Date today = new Date();

    long diff = today.getTime() - d1.getTime();

    System.out.println(/*ww  w.j  a va 2s.c  o m*/
            "The 21st century (up to " + today + ") is " + (diff / (1000 * 60 * 60 * 24)) + " days old.");
}

From source file:DateAdd.java

public static void main(String[] av) {
    //+// ww w. j  av a  2  s. co m
    /** Today's date */
    Date now = new Date();

    long t = now.getTime();

    t -= 700 * 24 * 60 * 60 * 1000;

    Date then = new Date(t);

    System.out.println("Seven hundred days ago was " + then);
    //-
}

From source file:MainClass.java

public static void main(String args[]) {

    Date date = new Date();

    long msec = date.getTime();

    msec += 100 * 24 * 60 * 60 * 1000L;/*from   w  ww .  j  av a 2  s. co m*/

    date.setTime(msec);

    System.out.println(date);
}

From source file:MainClass.java

public static void main(String args[]) {
    Date currentDate = new Date();

    long msec = currentDate.getTime();

    long days = msec / (24 * 60 * 60 * 1000);

    System.out.println(days);/*from  w  ww.j  a v a 2 s.com*/
}

From source file:Main.java

public static void main(String[] args) throws Exception {
    SimpleDateFormat sdf = new SimpleDateFormat("dd MM yyyy");
    Date dt1 = sdf.parse("22 02 2000");

    Date dt2 = sdf.parse("22 02 2010");

    long diff = dt2.getTime() - dt1.getTime();

    System.out.println("Days: " + diff / 1000L / 60L / 60L / 24L);
}

From source file:Main.java

public static void main(String[] args) throws Throwable {
    SimpleDateFormat format = new SimpleDateFormat("HH:mm:ss");
    Date date1 = format.parse("08:00:01");
    Date date2 = format.parse("23:00:05");
    Date date = new Date(date2.getTime() - date1.getTime());
    System.out.println(format.format(date));
}

From source file:Main.java

public static void main(String[] args) throws Exception {
    String today = "21/12/2007";

    DateFormat formatter = new SimpleDateFormat("dd/MM/yyyy");
    Date date = formatter.parse(today);
    long dateInLong = date.getTime();

    System.out.println("date = " + date);
    System.out.println("dateInLong = " + dateInLong);
}

From source file:Main.java

public static void main(String[] args) {
    int[] anArray = new int[1000];
    Random generator = new Random();
    for (int i = 0; i < 1000; i++) {
        anArray[i] = (generator.nextInt(1000) + 1);
    }//from   w w  w  .ja  v  a  2  s.  c  o  m
    Date before = new Date();
    Arrays.sort(anArray);
    Date after = new Date();
    System.out.println("milli seconds" + (after.getTime() - before.getTime()));
}