User Name Password Register
DaniWeb IT Discussion Community
All
What is DaniWeb IT Discussion Community?
You're currently browsing the JSP section within the Web Development category of DaniWeb, a massive community of 402,473 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 2,956 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our JSP advertiser: Lunarpages JSP Web Hosting
Views: 2007 | Replies: 3 | Solved
Reply
Join Date: Feb 2006
Posts: 9
Reputation: k_satish0101 is an unknown quantity at this point 
Rep Power: 0
Solved Threads: 0
k_satish0101 k_satish0101 is offline Offline
Newbie Poster

Help plz help me

  #1  
Mar 4th, 2006
i 'm getting the date in dateField variable after entering the code for converting the date into Simple Date Format

java.util.Date datefield2 = new java.util.Date(request.getParameter("dateField"));
java.text.SimpleDateFormat sdf = new java.text.SimpleDateFormat("EEEE,dd MMMM yyyy");
GregorianCalendar startDate = new GregorianCalendar(datefield2.getYear()+1900,datefield2.getMonth(),datefield2.getDay())


String reqdt=sdf.format(startDate.getTime())



i 'm not getting the exact date which i entered in dateField variable when i convert the format instead i'm getting different date

i need to compare the reqdt with the database which contains date's in Simple Date Format

how do i compare it ?

so plz help me in this regard

thank u in advance
AddThis Social Bookmark Button
Reply With Quote  
Join Date: Feb 2006
Posts: 1,378
Reputation: masijade is a jewel in the rough masijade is a jewel in the rough masijade is a jewel in the rough masijade is a jewel in the rough 
Rep Power: 8
Solved Threads: 120
masijade's Avatar
masijade masijade is offline Offline
Nearly a Posting Virtuoso

Re: plz help me

  #2  
Mar 7th, 2006
I won't claim to know why you are converting this to a GregorianCalendar, but I
will show you two things that you can try. In both these examples the line
from your post for creating "sdf" and "dateField2" should be kept and the line
creating startDate thrown out.

Here the first:
String reqdt = sdf.format(dateField2) ;

Here the second:
GregorianCalendar startDate = new GregorianCalendar( ) ;
startDate.setTime(dateField2) ;
String reqdt = sdf.format(startDate.getTime( ) ) ;
Last edited by masijade : Mar 7th, 2006 at 4:27 am. Reason: mistake
Java Programmer and Sun Systems Administrator

----------------------------------------------

Debugging is twice as hard as writing the code in the first place. Therefore, if you write the code as cleverly as possible, you are, by definition, not smart enough to debug it.
--Brian Kernighan
Reply With Quote  
Join Date: Mar 2006
Posts: 9
Reputation: Nilesh Pagar is an unknown quantity at this point 
Rep Power: 0
Solved Threads: 1
Nilesh Pagar Nilesh Pagar is offline Offline
Newbie Poster

Re: plz help me

  #3  
Mar 22nd, 2006
Just check out for the definition of getDay() method...........

public int getDay()......

Returns the day of the week represented by this date. The returned value
(0 = Sunday,
1 = Monday,
2 = Tuesday,
3 = Wednesday,
4 = Thursday,
5 = Friday,
6 = Saturday
)

represents the day of the week that contains or begins with the instant in time represented by this Date object, as interpreted in the local time zone.

Returns:
the day of the week represented by this date.

I think you know your problem now????? its correct actually, beacause its retrning you DAY of a week .... thats why u r getting changed date.....

Nilesh......
Reply With Quote  
Join Date: Mar 2006
Posts: 9
Reputation: Nilesh Pagar is an unknown quantity at this point 
Rep Power: 0
Solved Threads: 1
Nilesh Pagar Nilesh Pagar is offline Offline
Newbie Poster

Re: plz help me

  #4  
Mar 22nd, 2006
In oreder to do it correctly......

use getDate() method instead of getDay();

that will solve your problem................

This way....... it should be...............

GregorianCalendar startDate = new GregorianCalendar(datefield2.getYear()
+1900,datefield2.getMonth(),datefield2.getDate());



Nilesh ...........
Reply With Quote  
Reply

Only community members can participate in forum threads. You must register or log in to contribute.

DaniWeb JSP Marketplace
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)

 

Thread Tools Display Modes

Similar Threads
Other Threads in the JSP Forum

All times are GMT -4. The time now is 4:21 pm.
Forum system based on vBulletin Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
©2003 - 2008 DaniWeb® LLC