var now = new Date();
var dateString = now.getMonth() + "-" + now.getDate() + "-" + now.getFullYear() + " "
+ now.getHours() + ":" + now.getMinutes() + ":" + now.getSeconds();
here month is not displayed correctly.
Example if output is december it prints november
now.getMonth() +1 would display the correct month.
I am looking for a more better approach.
My application has to choose between two radiobuttons.the first option should return the current system date and time and other returns date and time selected from jsp.
On selecting either of the two options,it should return a date in a specific format to the controller.
getMonth()by definition returns month from 0 to 11.If you are not used to this, you can change the prototype of a
Dateobject:But this is not recommended at all.
Another approach
You can do this too if you want: