• Post Reply Bookmark Topic Watch Topic
  • New Topic

date type  RSS feed

 
Mark Hughes
Ranch Hand
Posts: 146
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hey guys,
I want to read in a string in the format of a date, dd/mm/yyyy and then convert it to a date type do i can compare it to the current date.
I was messing with the date methods such as setdate and stuff but it does not seem to allow me to set it to any specific date, can some one help me here.
I have the current date by doing this



So its the before method im having trouble with, it does not accept strings and im unsre how to initialise a custom date object, Any help

Mark
 
Mark Hughes
Ranch Hand
Posts: 146
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
i just came across this code which shows you how to set a custom date



This works but it would mean ill have to read in my string differently and break it down to put into that method GregorianCalendar, anyone know of a easier way to parse a custom string into date
 
Raghavan Muthu
Ranch Hand
Posts: 3389
Mac MySQL Database Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

You can use the parse method of DateFormat class which takes a String and gives you the java.util.Date value back.
 
Mark Hughes
Ranch Hand
Posts: 146
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Raghavan, thats seems to be doin the job for me

 
Raghavan Muthu
Ranch Hand
Posts: 3389
Mac MySQL Database Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
thats great..
 
Mark Hughes
Ranch Hand
Posts: 146
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
ah now im havin a similar problem with comparing the system time with a time the user enters.
basically i get reh system time the same way as above

Then the user enters the time as HH:MM and i parse that into a date object, but when i comapre the system time with the one i parse as follows

they are never equal cos it trys to compare down to the second and date even though i dont want to do that, any one know how to work around or good examples of what i want to do

Mark
 
Raghavan Muthu
Ranch Hand
Posts: 3389
Mac MySQL Database Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Mark,

You can very well and easily obtain the System time through



which gives you a long value which is typically in milliseconds. You can please check the JavaDoc of currentTimeMills() for further info.

HtH.
[ May 22, 2007: Message edited by: Raghavan Muthu ]
 
Mark Hughes
Ranch Hand
Posts: 146
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
cool thanks again Raghavan, appreciate your help

 
Raghavan Muthu
Ranch Hand
Posts: 3389
Mac MySQL Database Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
thats nice...

you are welcome Mark
 
Don't get me started about those stupid light bulbs.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!