Skip to Main Content

Java Programming

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!

How to get current date time in Javascript

807603Nov 2 2007 — edited Nov 2 2007
Hi All,
I need to dispaly the current date time in a jsp page.
I am calling javascript for calender.
My code is
 function getCurrentDateString() {	alert("getCurrentDateString()");  	var ff = new SimpleDateFormat("yyyy/MM/dd");    var n = new Date();    var result = ff.format(n);	alert('res->' + result);  return result;  }   
Its not working .
Anyone help me out ....

In java it works fine..
 import java.text.SimpleDateFormat;import java.util.*; public class Sample {    static public void displayDate() {       Date today;      String result;      SimpleDateFormat formatter;      formatter = new SimpleDateFormat("yyyy/MM/dd : HH/mm/ss");      today = new Date();      result = formatter.format(today);       System.out.println("Result: " + result);   }       static public void main(String[] args) {           displayDate();   }}
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Nov 30 2007
Added on Nov 2 2007
2 comments
8,394 views