• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

date type

 
Ranch Hand
Posts: 146
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Ranch Hand
Posts: 3389
Mac MySQL Database Tomcat Server
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
thats great..
 
Mark Hughes
Ranch Hand
Posts: 146
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
thats nice...

you are welcome Mark
 
reply
    Bookmark Topic Watch Topic
  • New Topic