Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to add 30 minutes to java.sql.Time object?

Tags:

java

time

I have this Time object:

Time myTime = java.sql.Time.valueOf("15:33:00");

How can I add 30 minutes to myTime in Java? That means the new time will be 16:03:00

like image 208
F. Fo Avatar asked Apr 25 '16 00:04

F. Fo


People also ask

How do I add timestamp to time?

Use the ADDTIME() function if you want to select a new datetime by adding a given time to a datetime/timestamp/time value. This function takes two arguments.

What is Java SQL time?

java.sql.Time. A thin wrapper around the java. util. Date class that allows the JDBC API to identify this as an SQL TIME value. The Time class adds formatting and parsing operations to support the JDBC escape syntax for time values.

Does Java SQL date have time?

No time data is kept. In fact, the date is stored as milliseconds since the 1st of January 1970 00:00:00 GMT and the time part is normalized, i.e. set to zero.


1 Answers

 java.sql.Time myTime = java.sql.Time.valueOf("15:33:00");
 LocalTime localtime = myTime.toLocalTime();
 localtime = localtime.plusMinutes(30);
 String output = localtime.toString();

you can get localTime straight away from the java.sql.time and you can use plusMinutes in LocalTime Api to add 30 minutes. this might help you check this

like image 183
Priyamal Avatar answered Sep 22 '22 13:09

Priyamal