Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

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

Posted on 2002-04-11
4
Medium Priority
?
220 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

Hire Technology Freelancers with Gigs

Work with freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely, and get projects done right.

Question has a verified solution.

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

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…
Introduction This article is the second of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article covers the basic installation and configuration of the test automation tools used by…
Viewers will learn about the regular for loop in Java and how to use it. Definition: Break the for loop down into 3 parts: Syntax when using for loops: Example using a for loop:
Viewers will learn how to properly install Eclipse with the necessary JDK, and will take a look at an introductory Java program. Download Eclipse installation zip file: Extract files from zip file: Download and install JDK 8: Open Eclipse and …
Suggested Courses

636 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