Solved

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

Posted on 2002-04-11
4
210 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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Introduction This article is the first of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article explains our test automation goals. Then rationale is given for the tools we use to a…
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…
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 learn about the scanner class in this video and are introduced to receiving user input for their programs. Additionally, objects, conditional statements, and loops are used to help reinforce the concepts. Introduce Scanner class: Importing…

772 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

14 Experts available now in Live!

Get 1:1 Help Now