Currently I am working on a Date Time Calcutions. It's suppose to be Current Time (JVm Time) - db_Transaction (UTIME) = lapse (hh:mm:ss)
Becoz of I lead of knowledge on this, spend so much time to research :( Now, Monday have to do presentation also. Well, anyone who able to help, PLEASE PLEASE PLEASE !!!
// Parse the Date. Date d = formatter.parse(dateInput + " " + timeInput);
// Create 2 Calendar objects. The current time is automatically read into a Calendar object.
GregorianCalendar calInput = new GregorianCalendar(); GregorianCalendar calSystem = new GregorianCalendar();
// Here we need to override the default time of the Calendar, which is read from the // current system time when you create the GregorianCalendar object.
calInput.setTime(d);
// Adding -1 to the DATE field of the system time, resulting a date of 24 hours ago...
calSystem.add(Calendar.DATE, -1);
// OK, finally this is it... calInput.before() will do the compare... // Because calSystem is actually 24 hours before the current time... // so calInput.before(calSystem) will just check if the time you input is 24 hours earlier.
if (calInput.before(calSystem)) { System.out.println("The time you input is 24 hours earlier than the current time!"); } else { System.out.println("OK, you entered a valid time."); } } catch (ParseException ex) { System.err.println("You must enter the right format of the date and time."); }
1. I would use a java bean for all of this, move the code out of jsp. 2. You prpbably are getting some exceptions somewhere, if you wrap everything in a try/catch/finally block this would help you track it down.
3. in the page directive you should specify a errorpage then in the error page you can catch the exception. You have a catch for the parse but what about the others ?
If you want to talk more about this you can email me at dhill@novell.com or yahoo messenger "ssswdon"
// Parse the Date. Date d = formatter.parse(dateInput + " " + timeInput);
// Create 2 Calendar objects. The current time is automatically read into a Calendar object.
calInput = new GregorianCalendar(); calSystem = new GregorianCalendar();
// Here we need to override the default time of the Calendar, which is read from the // current system time when you create the GregorianCalendar object.
calInput.setTime(d);
// Adding -1 to the DATE field of the system time, resulting a date of 24 hours ago...
calSystem.add(Calendar.DATE, -1);
// OK, finally this is it... calInput.before() will do the compare... // Because calSystem is actually 24 hours before the current time... // so calInput.before(calSystem) will just check if the time you input is 24 hours earlier.
if (calInput.before(calSystem)) { System.out.println("The time you input is 24 hours earlier than the current time!"); } else { System.out.println("OK, you entered a valid time."); }
} catch (ParseException ex) { ex.printStackTrace(); System.err.println("You must enter the right format of the date and time."); } %> <tr> <td><%= no%></td> <td><%= servicesname%></td> <td><%= servername %></td> <td><%= programname %></td> <td>test</td> <td><%= utime %></td>