Javatpoint Logo
Javatpoint Logo

Java SQL Date valueOf(String s) Method

The valueOf(String s) method of Java Date class converts a string in JDBC date escape format to a Date value.

Syntax

Parameters

s - It is a String object which represents a date in yyyy-[m]m-[d]d format. The leading zero for mm and dd may also be omitted.

Returns

This method returns a java.sql.Date object which represents the given date.

Example 1

Test it Now

Output:

Date = 1997-03-10

Java SQL Date valueOf(LocalDate date)

The valueOf(LocalDate date) method of Java Date class returns a Date object. Here Date object is obtained from an instance of Date from a LocalDate object which has the same year, month and day of the month value as the given LocalDate. The Provided LocalDate is interpreted as the local date in the local time zone.

Syntax

Parameters

date - It is a LocalDate to convert.

Returns

This method returns a Date object.

Exception

NUllPointerException is thrown if the date is null.

Example 2

Test it Now

Output:

Value of Local Date: 2018-09-01
Value of SQL Date: 2018-09-01

Next TopicJava SQL Date





Youtube For Videos Join Our Youtube Channel: Join Now

Feedback


Help Others, Please Share

facebook twitter pinterest

Learn Latest Tutorials


Preparation


Trending Technologies


B.Tech / MCA