CodesJava

Easy learning with example program codes

java sql date class


java.util.Date

The java.sql.Date class inherits java.util.Date class. It adds formatting and parsing operations to support the JDBC.

Constructor of java.sql.Date class:

    • Date(long milliseconds): Construct a Date using a milliseconds time value.

Java SQL Date Class Methods

Method Description
void setTime(long time) It changes the current sql date to given time.
Instant toInstant() It converts current sql date into Instant object.
LocalDate toLocalDate() It converts current sql date into LocalDate object.
String toString() It converts this sql date object to a string.
static Date valueOf(LocalDate date) It returns sql date object for the given LocalDate.
static Date valueOf(String date) It returns sql date object for the given String.

java.sql.date class example

package com.codesjava;
 
import java.sql.Date;
 
public class SQLDateTest {
	public static void main(String args[]){
		long millis=System.currentTimeMillis();  
        Date date=new Date(millis);  
        System.out.println(date);   
	}
}

Output:

2018-04-09

Java string to java.sql.date example

package com.codesjava;
 
import java.sql.Date;
 
public class StringToSQLDateTest {
	public static void main(String args[]){
	    String str="2018-04-09";  
	    //String to sql date conversion 
	    Date date=Date.valueOf(str);
	    System.out.println(date);    
	}
}

Output:

2018-04-09
Posted in Date   


Industrial Training

We offers Placement Oriented Training on Java, Spring, JSF, Hibernate, PHP, AngularJS, Angular 4, PLSQL, Oracle BI Publisher etc. We also provides Online training, please mail us at hr@codesjava.com.

Development

We also provides the Development services for Website Development , Java Development, PHP Development, Android App Development etc. You can contact us on hr@codesjava.com.

Copyright © 2019 CodesJava DMCA.com Protection Status SiteMap Reference: Java Wiki