-->
Skip to main content

Posts

Convert String to sql date in java 8 [2021]

Convert String to SQL date in java 8 [2021] In this tutorial, we will see how to convert string to SQL date in Java 8 with an example using the SQL Date class method. Contents Java SQL Date Example: Get Current Date String to SQL date in java 8 Conclusion References Java SQL Date Example: Get Current Date Let's see an example of how to get the current date using java SQL date. Example: import java.sql.Date; public class SqlDateExample { public static void main(String[] args) { long milliseconds = System.currentTimeMillis(); Date currentDate = new Date(milliseconds); System.out.println(currentDate); } } Output: 2021-07-23 String to SQL date in java 8 To Convert Java String to SQL date we will use java.sql.Date.valueOf(String s) method.  Example: import java.sql.Date; public class StringToSqlDate { public static void main(String[] args) { String stringDate = "2021-07-23"; System.out.println("String format date : "

Convert Java Instant to Date [2021]

Convert Java Instant to Date [2021] In this tutorial, We will Convert Java Instant to Date using Date.from(Instant instant) method. Java Instant to Date Example This example shows how to convert Java Instant to Date using Date.from(Instant instant) method. import java.time.Instant; import java.util.Date; public class JavaInstantNowToDate { public static void main(String[] args) { Instant instant = Instant.now(); System.out.println("Instant : " + instant); // Java Instant now to Date Date date = Date.from(instant); System.out.println("Java Instant to Date : " + date); } } Output: Instant : 2021-06-29T16:36:19.769Z Java Instant to Date : Tue Jun 29 16:36:19 IST 2021 Conclusion In this tutorial, we have covered how to convert Java Instant to Date using the Date class static method Date.from(Instant instant). Thanks for reading this tutorial so far. If you like this tutorial then please share it with your friends and colleagues. If you h

Convert calendar to date in java [2021]

Convert calendar to date in java [2021] In this tutorial, we will cover how to convert calendar to date in Java, Calendar class has static method Calendar.getInstance().getTime() which will give date class instance. Calendar to date in Java import java.util.Calendar; import java.util.Date; public class CalendarToDate { public static void main(String[] args) { //Creating calendar instance Calendar cal = Calendar.getInstance(); //Converting calendar to date Date date = cal.getTime(); //Output : Tue Jun 15 20:22:07 IST 2021 System.out.println(date); } } Output: Tue Jun 15 20:22:07 IST 2021 Conclusion In this tutorial, We have covered how to convert Calendar instance to date instance. Thanks for reading this tutorial so far. If you like this tutorial then please share it with your friends and colleagues. If you have any questions, doubts, suggestions, or feedback then please drop a comment and I'll try to answer your question. So what do you think about this