Set the timestamp to the current time in Java

I'm trying to set the current date and time in the Java ee7 web application to my Apache Derby database

I use time stamps in Java and Derby, so I don't have to worry about type conversion

However, I know that the only way to get the current date and time is through calendar Set (calendar time)

Is there an inherent way to set the current date and time of the timestamp, or do you need to use a converter?

Solution

You can use the date class to initialize to the current time, that is:

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

java. util. The calendar class is an abstract encapsulation of the date object Calendar provides getters and setters for date fields, that's all It comes at a price

Simple dates are ideal in your case

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>