my servlet print the previous month not the cuurent????

this is the code :
it should produce 11/4/2002
but it is printing :11/3/2002
what is the problem and how to solve it,
and if i want to print day like that : 11 april 2002

Calendar objCalendar=new GregorianCalendar();
             out.println("<b>"+objCalendar.get(Calendar.DAY_OF_MONTH) + "/"
              + objCalendar.get(Calendar.MONTH) + "/"
              + objCalendar.get(Calendar.YEAR)+"</b>");
star5Asked:
Who is Participating?
 
naveethCommented:
Calendar objCalendar=new GregorianCalendar();
           int intmonth = objCalendar.get(Calendar.MONTH)+1;
            out.println("<b>"+objCalendar.get(Calendar.DAY_OF_MONTH) + "/"
             + intmonth + "/"
             + objCalendar.get(Calendar.YEAR)+"</b>");
0
 
jerelwCommented:
In Java, the Months begin at zero.

To get 1 for January instead of zero, you have to add one to your Months.
0
 
bobbit31Commented:
or you could do:

DateFormat myDateFormat = new SimpleDateFormat("M/d/yyyy");
out.println myDateFormat.format(objCalendar.getTime());
0
 
Shinesh PremrajanEngineering ManagerCommented:
if any of the above script tips doesnt work
just check our server date because the date is printed
whats the date in server
ok
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.