Solved

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

Posted on 2002-04-11
4
211 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
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 9 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:shinuq
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

DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
json example 39 130
topping1 challenge 7 72
Spring Framework HTTPSession management 1 21
How to increase Spring boot/Tomcat max file upload size 2 16
Java functions are among the best things for programmers to work with as Java sites can be very easy to read and prepare. Java especially simplifies many processes in the coding industry as it helps integrate many forms of technology and different d…
In this post we will learn how to connect and configure Android Device (Smartphone etc.) with Android Studio. After that we will run a simple Hello World Program.
Video by: Michael
Viewers learn about how to reduce the potential repetitiveness of coding in main by developing methods to perform specific tasks for their program. Additionally, objects are introduced for the purpose of learning how to call methods in Java. Define …
Viewers will learn about if statements in Java and their use The if statement: The condition required to create an if statement: Variations of if statements: An example using if statements:

932 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

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now