Win a copy of The Little Book of Impediments (e-book only) this week in the Agile and Other Processes forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Retrieve value from a DateField

 
Kate Wilson
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi, I have a DateField which allows user to set both time and date. This set value is displayed on the screen. I want to validate the input values against a particular date. When I tried to print the set value using System.out.println(), I see that the type is set and not the actual set value. Can anyone tell me how to see the set value? Here's all the methods that I tried.
--------------------------------------
System.out.println("Date time " + pdatetime.DATE_TIME); // 3
System.out.println("time " + pdatetime.TIME); // 2
System.out.println("date " + pdatetime.DATE); // 1
System.out.println("get date " + pdatetime.getDate()); // address
System.out.println("get date toString " + pdatetime.getDate().toString()); // address- no diff
System.out.println("get input mode " + pdatetime.getInputMode()); // 3 for Date_Time
System.out.println("toString.length " + pdatetime.toString().length());
--------------------------------------------
Thanks,
Kate
 
Blake Minghelli
Ranch Hand
Posts: 331
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
A DateField stores its associated date via a java.util.Date object. Basically, a java.util.Date represents a point in time and is really nothing more than that point in time expressed in milliseconds.
So assuming pdatetime is the name of your DateField:

So I think that answers your basic question of how to seee the value of the DateField.
Now if you want to format that into something readable (unless you happen to be a math genius that can calculate the date in your head using the milliseconds), you'll need to create a java.util.Calendar object and build a "date string" using its fields. Let us know if you need help with that.
 
Kate Wilson
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Blake,
Thanks for the response. I'm able to do the comparison and the functionality is working fine now. However, i tried to print the value for my reference, using the java.util.Calendar object and it gives me error. Can you pls. help me with the retrieval of the date value in readable format?
Thanks,
Kate
 
Blake Minghelli
Ranch Hand
Posts: 331
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Here's some basic code that shows how to use a Calendar object to format and print a date:
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic