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();

    SimpleDateFormat sdf = new SimpleDateFormat("HH");
    System.out.println("hour in HH format : " + sdf.format(date));
}

From source file:Main.java

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

    Calendar calendar = Calendar.getInstance();
    calendar.add(Calendar.DATE, 1);
    Date tomorrow = calendar.getTime();

    if (tomorrow.after(today)) {
        System.out.println(tomorrow + " is after " + today);
    }/* www  .j av a2  s. c o m*/
}

From source file:Main.java

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

    SimpleDateFormat sdf = new SimpleDateFormat("Z");
    System.out.println("TimeZone in Z format : " + sdf.format(date));
}

From source file:Main.java

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

    Calendar calendar = Calendar.getInstance();
    calendar.add(Calendar.DATE, -1);
    Date yesterday = calendar.getTime();

    if (yesterday.before(today)) {
        System.out.println(yesterday + " is before " + today);
    }/*  w w w .  ja  v  a2s .co m*/
}

From source file:Main.java

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

    SimpleDateFormat sdf = new SimpleDateFormat("k");
    System.out.println("hour in k format : " + sdf.format(date));
}

From source file:Main.java

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

    SimpleDateFormat sdf = new SimpleDateFormat("zzz");
    System.out.println("TimeZone in z format : " + sdf.format(date));
}

From source file:Main.java

public static void main(String[] args) {

    // create a date
    Date date = new Date();

    // clone it to a second date
    Object date2 = date.clone();//from   www .  j a  v a2 s . c  om

    // print the results
    System.out.println("Original Date:" + date.toString());
    System.out.println("Cloned date :" + date2.toString());
}

From source file:Main.java

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

    String strDateFormat = "h";
    SimpleDateFormat sdf = new SimpleDateFormat(strDateFormat);
    System.out.println("hour in h format : " + sdf.format(date));
}

From source file:Main.java

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

    SimpleDateFormat sdf = new SimpleDateFormat("MMM");

    System.out.println("Current Month in MMM format : " + sdf.format(date));
}

From source file:Main.java

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

    SimpleDateFormat sdf = new SimpleDateFormat("s");
    System.out.println("seconds in s format : " + sdf.format(date));
}