So I'm about ready to drive my car off a bridge and really need an outside opinion on how to do this, I have been struggling for days to find any kind of valid solution and feel as though it's simply all my pent up stress holding me back. That being said any help is appreciated.
Preface:
My application handles customers in a sql database and users can select a customer and upload an appointment to another table.
Where I am running into serious mental blocks is converting the dates properly, as well as querying the SQL. I am using JavaFX datepicker, which returns a Date() in the form 'YYYY-MM-DD', example for today would be '11/25/2018'. Appointments are stored in UTC, which leads me to my first problem.
If an employee selects a date, say December 1st, 2018, this date needs to be converted to UTC and the full 24 hours need to be queried from the database.
Question 1:
So my idea was get the Date() object from datepicker which is in the above form, then adding " 00:00:00" to it and attempting to convert to UTC, but I have no idea how to do this and can't find anything relevant, how would you go about doing this.
Question 2:
I need do the same as above, but with the Date() + 1 full day, so if the original was December 1, 2018 at 00:00:00 my time, then this would be December 2, 2018 at 00:00:00 my time, I can't find any real way to add a day to a Date() object properly.
Question 3:
The database holds a start business time, in UTC just for simplicity say its "00:00:00" and extends 8 hours so the end time would be "08:00:00", how do I return all appointment entries that fall between these times from question 2, assuming the start/end times are in datetime format.
Please, I don't know who else to ask. I have an application that is crippled because I simply can't figure out a solution to such a stupid simple question.
Here's my attempt at question 1/2 with output
Output:test("2018-12-01"); private static void test(String date){ try{ DateFormat utcFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); utcFormat.setTimeZone(TimeZone.getTimeZone("UTC")); Date startDate = utcFormat.parse(date + " 00:00:00"); System.out.println(startDate); LocalDateTime today = convertToLocalDateTimeViaSqlTimestamp(startDate); today = today.plusDays(1); System.out.println(convertToDateViaSqlTimestamp(today)); }catch(Exception e){ } } private static Date convertToDateViaSqlTimestamp(LocalDateTime dateToConvert) { return java.sql.Timestamp.valueOf(dateToConvert); } private static LocalDateTime convertToLocalDateTimeViaSqlTimestamp(Date dateToConvert) { return new java.sql.Timestamp(dateToConvert.getTime()).toLocalDateTime(); }
Fri Nov 30 16:00:00 PST 2018
2018-12-01 16:00:00.0