Skip to Main Content

Java EE (Java Enterprise Edition) General Discussion

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Going nuts with JSTL's fmt:formatDate

843840Mar 13 2008 — edited Mar 15 2008
Hello everybody,

I'm feeling kind of embarrassed to ask this question but I'm stuck run down with my nerves...It is supposed to be a very simple task formatting a Date object into a string. That's at least what I am trying to do in my JSP. I want to set a javascript variable with a JSTL generated value (the formatted date).My code looks like this:
<jsp:root xmlns:jsp="http://java.sun.com/JSP/Page" version="1.2"
xmlns:c="http://java.sun.com/jsp/jstl/core"
xmlns:fmt="http://java.sun.com/jsp/jstl/fmt"
[...]
<script type="text/javascript">
<jsp:useBean id="now" class="java.util.Date" />
<fmt:formatDate value="${now}" pattern="EEE, d MMM yyyy HH:mm:ss" />

var currenttime = "<c:out value="${now}" />"
[,,,]

the generated code looks like this:

var currenttime = "Fri Mar 14 02:31:10 CET 2008"

which is technically ok but the date is not really exactly what I set the pattern for. Regardless what pattern I use (or if I use one at all), the output stays exactly the same. I even copy pasted some code from tutorial website with no different result.

Am I missing something here or is there anything completely wrong with this approach?

I would appreciate any help because I'm really stuck here...;(
Thanks in advance!

Cheers,
Joerg
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Apr 12 2008
Added on Mar 13 2008
2 comments
535 views