- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Convert the Current Time to a java.sql.Date Object
Firstly, create a Calendar class object.
Calendar calendar = Calendar.getInstance();
Now, import the following package.
import java.sql.Date;
Using a Date class now and creating an object would belong to the above package. Convert the current time to the java.sql.Date Object.
Date sqlDate = new Date((calendar.getTime()).getTime());
The following is an example.
Example
import java.util.Calendar; import java.sql.Date; import java.text.ParseException; public class Demo { public static void main(String[] args) throws ParseException { Calendar calendar = Calendar.getInstance(); // object Date sqlDate = new Date((calendar.getTime()).getTime()); System.out.println(sqlDate); } }
Output
2018-11-19
- Related Articles
- Java Program to convert from a java.util.Date Object to a java.sql.Date Object
- Convert the value of the current DateTime object to a Windows file time in C#
- Convert string of time to time object in Java
- How do I create a java.sql.Date object in Java?
- How to get LocalDateTime object from java.sql.Date using JDBC?
- How to convert a time series object to a vector in R?
- Convert the value of the current DateTime object to UTC in C#
- Python Pandas - Get the current date and time from Timestamp object
- Select current time with MySQL now() and convert it to GMT 0?
- How to convert ISO 8601 string to Date/time object in Android?
- How to convert ISO 8601 String to Date/Time object in Android using Kotlin?
- Convert object to a Map - JavaScript
- Forming the nearest time using current time in JavaScript
- How to set current time to some other time in JavaScript?
- Java Program to display Current Time in another Time Zone

Advertisements