java.sql.DateThe java.sql.Date class represents the only date in Java. It inherits the java.util.Date class. The java.sql.Date instance is widely used in the JDBC because it represents the date that can be stored in a database. Some constructors and methods of java.sql.Date class has been deprecated. Here, we are not giving the list of any deprecated constructor and method. java.sql.Date Constructor
java.sql.Date Methods
java.sql.Date Example: get current dateLet's see the example to print date in java using the java.sql.Date class. FileName: SQLDateExample.java Test it NowOutput: 2015-03-30 Java String to java.sql.Date ExampleLet's see the example to convert string into java.sql.Date using the valueOf() method. FileName: StringToSQLDateExample.java Test it NowOutput: 2015-03-31 java.sql.Date Example: void setTime()Let's see the working of the setTime() method. FileName: SetTimeExample.java Output: Initial date is: Fri Nov 26 11:52:20 GMT 2021 Date after the setting the time is: Thu Jan 01 00:16:40 GMT 1970 java.sql.Date Example: void toLocalDate()Let's see the working of the toLocalDate() method. FileName: ToLocalDateExample.java Output: The date is: 2021-11-26 java.sql.Date Example: void toInstant()Let's see the working of the toInstant() method. FileName: ToInstantExample.java Output: The original Date is: Thu Aug 12 12:41:01 GMT 2021 The instant is: 2021-08-12T12:41:01.635Z
Next TopicJava Calendar
|