I'm glad that it works! I have remembered now why I use the same Date twice (the way you do it just once is neater than mine): the first Date allows the calendar to decide whether it is in summer time or not (for those time zones that have a summer daylight saving time). The second Date is the one converted to a string.
On Aug 9, 3:28 pm, Stephen <[email protected]> wrote: > Thanks for your reply. Based on your input I ended up using the > following: > > <% > // Create a calendar to work with. > GregorianCalendar gc = new GregorianCalendar(Locale.US); > > // Create a timezone object to set ont eh calendar. > TimeZone tz = TimeZone.getTimeZone("America/Chicago"); > > // Set the timezone. > gc.setTimeZone(tz); > > // Set the date. > gc.setTime(new Date()); > > // Format the date > SimpleDateFormat sdf = new SimpleDateFormat("EEE, MMM d, yyyy > hh:mm:ss a z"); > > // Give the date format a calendar to work with. > sdf.setCalendar(gc); > > // Create a string out of the date for display on the page. > String sDate = sdf.format(sdf.getCalendar().getTime()); > %> > > Works good! Thanks again for your help. =) > > On Aug 8, 3:30 am, Ian Marshall <[email protected]> wrote: > > > Correction: > > > I use the following: > > > Date dtDateTime = new Date(); // Or whatever else it is to be > > > GregorianCalendar gcUK = new GregorianCalendar(Locale.UK); > > TimeZone tzUK = TimeZone.getTimeZone("Europe/London"); > > gcUK.setTimeZone(tzUK); > > gcUK.setTime(dtDateTime); > > > DateFormat dfUK = > > SimpleDateFormat.getDateTimeInstance(SimpleDateFormat.MEDIUM, > > SimpleDateFormat.MEDIUM, Locale.UK); > > dfUK.setCalendar(gcUK); > > String sDate = dfUK.format(dtDateTime); > > > I cannot remember now why I repeat "dtDateTime", but it works for me. > > > On Aug 7, 8:28 am, Ian Marshall <[email protected]> wrote: > > > > The UTC time is the same everywhere at the same time. > > > > The trick is to format the date-time for a time zone. > > > > I use the following: > > > > GregorianCalendar gcUK = new GregorianCalendar(Locale.UK); > > > TimeZone tzUK = TimeZone.getTimeZone("Europe/London"); > > > gcUK.setTimeZone(tzUK); > > > gcUK.setTime(new Date()); > > > > DateFormat dfUK = > > > SimpleDateFormat.getDateTimeInstance(SimpleDateFormat.MEDIUM, > > > SimpleDateFormat.MEDIUM, Locale.UK); > > > dfUK.setCalendar(gcUK); > > > String sDate = dfUK.format(dtDateTime); > > > > Choose your own locale and time zone. Enjoy? > > > > On Aug 6, 5:38 pm, Stephen <[email protected]> wrote: > > > > > If I run : > > > > > Date now = new Date(); > > > > System.out.println(now); > > > > > from the main method of a plain java class I get : > > > > Fri Aug 06 11:33:00 CDT 2010 as expected. > > > > > If I run that same code in a JSP app engine gives me : > > > > Fri Aug 06 11:33:00 UTC 2010 > > > > > Run that same JSP on tomcat and again I get : > > > > Fri Aug 06 11:33:00 CDT 2010 as expected. > > > > > Even if I try to set the timezone manually I still get UTC from a JSP > > > > hosted by app engine. > > > > Any ideas what is going on here? > > > > > Thanks in advance.- Hide quoted text - > > > - Show quoted text - > > -- You received this message because you are subscribed to the Google Groups "Google App Engine for Java" group. To post to this group, send email to [email protected]. To unsubscribe from this group, send email to [email protected]. For more options, visit this group at http://groups.google.com/group/google-appengine-java?hl=en.
