w3resource

Java Date.toString()Method

public String toString()

The toString() method is used to convert an Date object to a string of the form: dow mon dd hh:mm:ss zzz yyyy

Where:

  • dow is the day of the week (Sun, Mon, Tue, Wed, Thu, Fri, Sat).
  • mon is the month (Jan, Feb, Mar, Apr, May, Jun, Jul, Aug, Sep, Oct, Nov, Dec).
  • dd is the day of the month (01 through 31), as two decimal digits.
  • hh is the hour of the day (00 through 23), as two decimal digits.
  • mm is the minute within the hour (00 through 59), as two decimal digits.
  • ss is the second within the minute (00 through 61, as two decimal digits.
  • zzz is the time zone (and may reflect daylight saving time). Standard time zone abbreviations include those recognized by the method parse. If time zone information is not available, then zzz is empty - that is, it consists of no characters at all.
  • yyyy is the year, as four decimal digits.

Package: java.util

Java Platform: Java SE 8

Syntax:

toString()

Return Value:
a string representation of this date.

Return Value Type: string

Example: Java Date.toString() Method

import java.util.Date;
public class Main {
   public static void main(String[] args) {

      // create a date
       Date date = new Date(2012, 2, 2);

      // Converts the said Date object to String
      String str_date = date.toString();
      System.out.println(str_date);
   }
}
 

Output:

Sat Mar 02 00:00:00 UTC 3912

Java Code Editor:

Previous:toInstant Method
Next:Arraydeque Class Methods Home



Become a Patron!

Follow us on Facebook and Twitter for latest update.

It will be nice if you may share this link in any developer community or anywhere else, from where other developers may find this content. Thanks.

https://www.w3resource.com/java-tutorial/util/date/java_date_tostring.php