•
•
•
•
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
![]() |
•
•
Join Date: Feb 2006
Posts: 9
Reputation:
Rep Power: 0
Solved Threads: 0
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
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
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( ) ) ;
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
----------------------------------------------
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
•
•
Join Date: Mar 2006
Posts: 9
Reputation:
Rep Power: 0
Solved Threads: 1
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......
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......
•
•
Join Date: Mar 2006
Posts: 9
Reputation:
Rep Power: 0
Solved Threads: 1
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 ...........
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 ...........
![]() |
•
•
•
•
•
•
•
•
DaniWeb JSP Marketplace
•
•
•
•
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
Similar Threads
- can someone plz help me with this? (Visual Basic 4 / 5 / 6)
- I NEED SUPPORT **"IMPORTANT"** PLZ HELP (Windows NT / 2000 / XP / 2003)
- Windows media player (Windows NT / 2000 / XP / 2003)
- Bridge.dll...Make it go away, Plz (Viruses, Spyware and other Nasties)
- can sum1 look @ dis plz (Viruses, Spyware and other Nasties)
- Hijackthis log file - plz help (Viruses, Spyware and other Nasties)
- IE not working...PLZ help :cry: (Web Browsers)
- PLZ help it's urgent! (Web Browsers)
- plz help ppl...... (Computer Science and Software Design)
Other Threads in the JSP Forum
- Previous Thread: reading .csv using jsp
- Next Thread: Need JavaScript/Firefox HELP



Linear Mode