?
Solved

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

Posted on 2002-04-11
4
Medium Priority
?
218 Views
Last Modified: 2013-11-24
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>");
0
Comment
Question by:star5
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
4 Comments
 
LVL 3

Expert Comment

by:jerelw
ID: 6934723
In Java, the Months begin at zero.

To get 1 for January instead of zero, you have to add one to your Months.
0
 
LVL 18

Expert Comment

by:bobbit31
ID: 6934748
or you could do:

DateFormat myDateFormat = new SimpleDateFormat("M/d/yyyy");
out.println myDateFormat.format(objCalendar.getTime());
0
 
LVL 1

Accepted Solution

by:
naveeth earned 36 total points
ID: 6935954
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
 
LVL 17

Expert Comment

by:Shinesh Premrajan
ID: 6936683
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

Featured Post

Quick Start: DOCKER

Sometimes you just need a Quick Start on a topic in order to begin using it.. this is just what you need to know to get up and running with Docker!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Are you developing a Java application and want to create Excel Spreadsheets? You have come to the right place, this article will describe how you can create Excel Spreadsheets from a Java Application. For the purposes of this article, I will be u…
Introduction Java can be integrated with native programs using an interface called JNI(Java Native Interface). Native programs are programs which can directly run on the processor. JNI is simply a naming and calling convention so that the JVM (Java…
Viewers learn about the “for” loop and how it works in Java. By comparing it to the while loop learned before, viewers can make the transition easily. You will learn about the formatting of the for loop as we write a program that prints even numbers…
Viewers will learn about basic arrays, how to declare them, and how to use them. Introduction and definition: Declare an array and cover the syntax of declaring them: Initialize every index in the created array: Example/Features of a basic arr…
Suggested Courses
Course of the Month14 days, 1 hour left to enroll

800 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question