Any idea why the format is not consistent in google spreadsheets and how we can ensure it is?
Apparently you have a bug in the code that is forming those datetime strings: it always puts "pm" at the end. There is no such time as "15:39 pm", so Google does not parse this as a date time value, treating it just as a string (hence, left-align).
To fix this, simply drop "pm" part, since you are evidently using 24-hour time rather than 12-hour. Better yet, use ISO formatting:
which should be correctly parsed by Google Sheets independent of your locale.