i am working on a website (angular 9, spring boot).
i need a user to be able to send me a Date AND Time of a certain event,
while on the java side i am working with java.sql.TimeStamp
and in angular i am using both NgbDatepicker
(for date) and Time
(for hours&minutes). what i want to do is to combine them to be the same as the java.sql.TimeStamp
with the TimeZone.
is there any idea that should help me, or should i maybe send them as they are to the java and create a new TimeStamp each time before putting into the DB?
Asked
Active
Viewed 902 times
-1

user3469465
- 39
- 7
-
I recommend you don’t use `java.sql.TimeStamp`. That class is poorly designed and long outdated. Instead use `OffsetDateTime` or `LocalDateTime`, both from [java.time, the modern Java date and time API](https://docs.oracle.com/javase/tutorial/datetime/). Since JDBC 4.2 you can directly save these types to your SQL database. – Ole V.V. Jun 02 '20 at 19:33
1 Answers
1
I had the same promblem: My solution: I got a 'date' (as ISO 8601 string) from backend. In the frontend I created a second variable (a copy): One copy for date picker and one for time input. Before sending back to backend I joined these two values into one iso string.
const date = new Date(datevalue); // datevalue from datepicker
const hhmm = timevalue.split(':');
date.setHours(parseInt(hhmm[0], 10));
date.setMinutes(parseInt(hhmm[1], 10));
date.setSeconds(0);
date.setMilliseconds(0);
this.resultingDate = date;
In my solution :
date: input matDatepicker
time: input type="time"

Marc
- 1,836
- 1
- 10
- 14