Java Date.toString()

Syntax

Date.toString() has the following syntax.

public String toString()

Example

In the following code shows how to use Date.toString() method.


// w  ww.  j  ava  2 s  .c o  m
import java.util.Date;

public class Main {

   public static void main(String[] args) {

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

      // print the string representation
      System.out.println("String :  " + date.toString());
   }
}

The code above generates the following result.