Generally, high level languages have built-in date and time formatting, allowing you to present dates and times in virtually any manner you'd like. On the occasions that a language doesn't have such built-in support, it's fairly easy to write a method to do it for you. Going this route, as Jani's colleague did, is probably not the best way to go ...
try { cal.setTime(reservationTimestamp); cal.add(Calendar.HOUR, -2); Minute = cal.get(Calendar.MINUTE); Hour = cal.get(Calendar.HOUR); Day = cal.get(Calendar.DATE); Month = cal.get(Calendar.MONTH)+1; Year = cal.get(Calendar.YEAR); if (cal.get(Calendar.AM_PM) == 0) { if (Hour == 0) { tempHour = "00"; } if (Hour == 1) { tempHour = "01"; } if (Hour == 2) { tempHour = "02"; } if (Hour == 3) { tempHour = "03"; } if (Hour == 4) { tempHour = "04"; } if (Hour == 5) { tempHour = "05"; } if (Hour == 6) { tempHour = "06"; } if (Hour == 7) { tempHour = "07"; } if (Hour == 8) { tempHour = "08"; } if (Hour == 9) { tempHour = "09"; } if (Hour == 10) { tempHour = "10"; } if (Hour == 11) { tempHour = "11"; } } if (cal.get(Calendar.AM_PM) == 1) { if (Hour == 0) { tempHour = "12"; } if (Hour == 1) { tempHour = "13"; } if (Hour == 2) { tempHour = "14"; } if (Hour == 3) { tempHour = "15"; } if (Hour == 4) { tempHour = "16"; } if (Hour == 5) { tempHour = "17"; } if (Hour == 6) { tempHour = "18"; } if (Hour == 7) { tempHour = "19"; } if (Hour == 8) { tempHour = "20"; } if (Hour == 9) { tempHour = "21"; } if (Hour == 10) { tempHour = "22"; } if (Hour == 11) { tempHour = "23"; } if (Hour == 12) { tempHour = "00"; } } tempMinute = ""+Minute; if (Minute == 0) { tempMinute = "00"; } if (Minute == 1) { tempMinute = "01"; } if (Minute == 2) { tempMinute = "02"; } if (Minute == 3) { tempMinute = "03"; } if (Minute == 4) { tempMinute = "04"; } if (Minute == 5) { tempMinute = "05"; } if (Minute == 6) { tempMinute = "06"; } if (Minute == 7) { tempMinute = "07"; } if (Minute == 8) { tempMinute = "08"; } if (Minute == 9) { tempMinute = "09"; } if (Month == 1) { tempMonth = "1"; } if (Month == 2) { tempMonth = "2"; } if (Month == 3) { tempMonth = "3"; } if (Month == 4) { tempMonth = "4"; } if (Month == 5) { tempMonth = "5"; } if (Month == 6) { tempMonth = "6"; } if (Month == 7) { tempMonth = "7"; } if (Month == 8) { tempMonth = "8"; } if (Month == 9) { tempMonth = "9"; } insertTimeStamp = ""+Year+"."+Month+"."+Day+""+tempHour+":"+tempMinute; } catch (Exception e) { insertTimeStamp = "N/A"; } try { cal.setTime(cancellationTimestamp); cal.add(Calendar.HOUR, -2); Minute = cal.get(Calendar.MINUTE); Hour = cal.get(Calendar.HOUR); Day = cal.get(Calendar.DATE); Month = cal.get(Calendar.MONTH)+1; Year = cal.get(Calendar.YEAR); if (cal.get(Calendar.AM_PM) == 0) { if (Hour == 0) { tempHour = "00"; } if (Hour == 1) { tempHour = "01"; } if (Hour == 2) { tempHour = "02"; } if (Hour == 3) { tempHour = "03"; } if (Hour == 4) { tempHour = "04"; } if (Hour == 5) { tempHour = "05"; } if (Hour == 6) { tempHour = "06"; } if (Hour == 7) { tempHour = "07"; } if (Hour == 8) { tempHour = "08"; } if (Hour == 9) { tempHour = "09"; } if (Hour == 10) { tempHour = "10"; } if (Hour == 11) { tempHour = "11"; } } if (cal.get(Calendar.AM_PM) == 1) { if (Hour == 0) { tempHour = "12"; } if (Hour == 1) { tempHour = "13"; } if (Hour == 2) { tempHour = "14"; } if (Hour == 3) { tempHour = "15"; } if (Hour == 4) { tempHour = "16"; } if (Hour == 5) { tempHour = "17"; } if (Hour == 6) { tempHour = "18"; } if (Hour == 7) { tempHour = "19"; } if (Hour == 8) { tempHour = "20"; } if (Hour == 9) { tempHour = "21"; } if (Hour == 10) { tempHour = "22"; } if (Hour == 11) { tempHour = "23"; } if (Hour == 12) { tempHour = "00"; } } tempMinute = ""+Minute; if (Minute == 0) { tempMinute = "00"; } if (Minute == 1) { tempMinute = "01"; } if (Minute == 2) { tempMinute = "02"; } if (Minute == 3) { tempMinute = "03"; } if (Minute == 4) { tempMinute = "04"; } if (Minute == 5) { tempMinute = "05"; } if (Minute == 6) { tempMinute = "06"; } if (Minute == 7) { tempMinute = "07"; } if (Minute == 8) { tempMinute = "08"; } if (Minute == 9) { tempMinute = "09"; } if (Month == 1) { tempMonth = "1"; } if (Month == 2) { tempMonth = "2"; } if (Month == 3) { tempMonth = "3"; } if (Month == 4) { tempMonth = "4"; } if (Month == 5) { tempMonth = "5"; } if (Month == 6) { tempMonth = "6"; } if (Month == 7) { tempMonth = "7"; } if (Month == 8) { tempMonth = "8"; } if (Month == 9) { tempMonth = "9"; } updateTimeStamp = ""+Year+"."+Month+"."+Day+""+tempHour+":"+tempMinute; } catch (Exception e) { updateTimeStamp = "N/A"; }
Also a quick thanks to Chad Grant, who helped out with a serializer hack. It works great. I used control characters \u0011 and \u0012 as delimiters and added a type to allow for casting on the way back (as it aparantly wasn't all strings).
[Advertisement]
BuildMaster allows you to create a self-service release management platform that allows different teams to manage their applications. Explore how!