How to convert java.util.date to java.sql.Timestamp?

I wish to convert the java.util.date to java.sql.Timestamp(set all the hours, minutes, seconds, nanoseconds to 0), how to do this?
LVL 9
william007Asked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

CEHJCommented:
long time = date.getTime();
CEHJCommented:
Sorry

timestamp = new Timestamp(date.getTime());

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
rama_krishna580Commented:
Hi,

  private final java.sql.Timestamp sqlTimestamp(java.util.Date utilDate)
 {
    return new java.sql.Timestamp(utilDate.getTime());
 }

R.K
Exploring SharePoint 2016

Explore SharePoint 2016, the web-based, collaborative platform that integrates with Microsoft Office to provide intranets, secure document management, and collaboration so you can develop your online and offline capabilities.

william007Author Commented:
Thanks:-)
el_diosCommented:
Hi CEHJ,
I would agree with CEHJ.

You can do it another way if you want to use the constructor you have shown:
Timestamp(int year, int month, int date, int hour, int minute, int second, int nano)
then you would need to do :

Calendar cal = Calendar.getInstance();
cal.setTime(date);
timestamp = new Timestamp(cal.get(Calendar.HOUR), .......,.....);


Cheers!
CEHJCommented:
:-)
CEHJCommented:
Zeroing the time is fairly simple:

                  Calendar cal = new GregorianCalendar(2006, 3, 19);
                  java.sql.Timestamp t = new java.sql.Timestamp(cal.getTimeInMillis());
                  System.out.println(t);
william007Author Commented:
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Java

From novice to tech pro — start learning today.