Example usage for java.util Date Date

List of usage examples for java.util Date Date

Introduction

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

Prototype

public Date() 

Source Link

Document

Allocates a Date object and initializes it so that it represents the time at which it was allocated, measured to the nearest millisecond.

Usage

From source file:Main.java

public static void main(String[] args) {

    Date date = new Date();
    Date date2 = new Date();

    // Check if they are equal
    boolean check = date.equals(date2);

    // print the result
    System.out.println("Dates are equal:" + check);

}

From source file:Main.java

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

    Date d2 = new Date();
    System.out.println("First Date : " + d1);
    System.out.println("Second Date : " + d2);

    int results = d1.compareTo(d2);
    if (results > 0) {
        System.out.println("after");
    } else if (results < 0) {
        System.out.println("before");
    } else {//from w ww.  j a v a 2 s.c  o m
        System.out.println("Both dates are equal");
    }
}

From source file:Main.java

public static void main(String[] args) throws Exception {
    Date d = new Date();
    Class cls = d.getClass();/*from   w  ww. jav a  2s . c o m*/
    System.out.println("Time = " + d.toString());

    Object obj = cls.newInstance();
    System.out.println("Time = " + obj);
}

From source file:MyPack.Main.java

public static void main(String args[]) {
    System.out.println(new Date());
}

From source file:Main.java

public static void main(String[] args) {

    long timeInMilliseconds = new Date().getTime();

    System.out.println("Time in milliseconds is : " + timeInMilliseconds);

}

From source file:Main.java

public static void main(String[] args) {

    Date date = new Date();
    Date date2 = new Date();

    // make 3 comparisons with them
    int comparison = date.compareTo(date2);
    int comparison2 = date2.compareTo(date);
    int comparison3 = date.compareTo(date);

    // print the results
    System.out.println("Comparison Result:" + comparison);
    System.out.println("Comparison2 Result:" + comparison2);
    System.out.println("Comparison3 Result:" + comparison3);

}

From source file:Main.java

public static void main(String[] args) {
    System.out.println(convertToSqlDate(new Date()));
}

From source file:Main.java

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

    String strDate = DateFormat.getDateInstance(DateFormat.FULL).format(date);
    System.out.println(strDate);/*from   w  ww  .j  av a  2 s .com*/
}

From source file:Main.java

public static void main(String[] argv) {

    System.out.println(new Date().toInstant().atZone(ZoneId.systemDefault()).toLocalDate());
}

From source file:Main.java

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

    String strDate = DateFormat.getDateInstance(DateFormat.DEFAULT).format(date);
    System.out.println(strDate);//w  w w . jav a  2 s  .com
}