0

I have a small problem here, I am passing a list with some events to JSP with Struts2, the list contains a row with events start time. I need to calculate this time by GMT, because of GMT value from cookies which was set by the user. The problem is the time row I am getting from database is in String format (why? too much to tell) something like 01:00, so, any ideas or advices how can I? maybe some sort of JS or jQ, or server-side solutions?

Thanks

Denees
  • 9,100
  • 13
  • 47
  • 76

1 Answers1

3

You can use SimpleDateFormat to parse the string that was retrieve from the database. In your example the pattern to parse 01:00 will be HH:mm because it is hour and minutes.

String strFromDB = "01/29/02 01:00";
DateFormat formatter = new SimpleDateFormat("MM/dd/yy HH:mm");
Date date = (Date)formatter.parse(strFromDB);

For reference http://download.oracle.com/javase/1.5.0/docs/api/java/text/SimpleDateFormat.html

zawhtut
  • 8,335
  • 5
  • 52
  • 76