This week's book giveaway is in the Java 8 forum.
We're giving away four copies of Java 8 in Action and have Raoul-Gabriel Urma, Mario Fusco, and Alan Mycroft on-line!
See this thread for details.
The moose likes JSP and the fly likes How to get current date in JS Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Java 8 in Action this week in the Java 8 forum!
JavaRanch » Java Forums » Java » JSP
Reply locked New topic
Author

How to get current date in JS

angelin precilla
Ranch Hand

Joined: Sep 11, 2007
Posts: 33
Hi All,
I need to dispaly the current date time in a jsp page.
I am calling javascript for calender.
My code is

Its not working .
Anyone help me out ....

In java it works fine..
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 39568
    
  27
JavaScript has little to do with Java, despite its name. You can't use Java classes like SimpleDateFormat in JS. If the format you're getting from "new Date().toString()" is not sufficient, you'll need to do string manipulation to transform it.

Alternatively, Java code in the JSP page can embed the formatted date string inside the script:


[ November 02, 2007: Message edited by: Ulf Dittmer ]

Ping & DNS - updated with new look and Ping home screen widget
angelin precilla
Ranch Hand

Joined: Sep 11, 2007
Posts: 33
How to perform localization in date time using jsp
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 39568
    
  27
Let's continue the discussion about localization in this duplicate thread.
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: How to get current date in JS
 
Similar Threads
Date Question
Date Format ,Please help!
how to change a date in desired format
Convert the String to date format
Getting current date