I have two dates with time values. I need to combine date from one and time from another and make third date and time of those.
Here is the JSON:
"block_times": [
{
"id": 63672,
"name": "One hour blocked time",
"all_day": false,
"start_date": "07/07/2020",
"end_date": "07/07/2020",
"start_time": "2000-01-01T16:00:00.000-06:00",
"end_time": "2000-01-01T17:00:00.000-06:00",
"note": "One hour block time",
"account_id": 1,
"service_routes_id": 4502,
"created_at": "2020-07-07T10:50:30.599-05:00",
"updated_at": "2020-07-07T10:50:30.599-05:00"
}
]
I need to get date from start_date
and I need to get time from start_time
and combine them together with date and time value.
I have the following code:
public static Date convertBlockedTimeToUserTime(String startTimeStr, String startDateStr) {
SimpleDateFormat dateFormat = new SimpleDateFormat(getDateTimeFormat(), Locale.US);
SimpleDateFormat startDateFormatInitial = new SimpleDateFormat("MM/dd/yyyy", Locale.US);
SimpleDateFormat startDateFormatFinal = new SimpleDateFormat("yyyy-MM-dd", Locale.US);
SimpleDateFormat startTimeFormat = new SimpleDateFormat(getTimeFormat(), Locale.US);
try {
String resultStartDate = startDateFormatFinal.format(startDateFormatInitial.parse(startDateStr));
String resultStartTime = startTimeFormat.format(dateFormat.parse(startTimeStr));
String result = resultStartDate+"T"+resultStartTime;
return dateFormat.parse(result);
} catch (ParseException e) {
e.printStackTrace();
return null;
}
I get this result: 2020-07-07T11:00:00.000+01:00
and this is wrong since my current time zone is GMT +2, so it should be like this: 2020-07-07T10:00:00.000+02:00
.
Can anyone help me to find the problem?