angularspring-boottimestampngb-datepicker

about Java.sql.TimeStamp and angular


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?


Solution

  • 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"