• 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
  • Tim Cooke
  • paul wheaton
  • Jeanne Boyarsky
  • Ron McLeod
Sheriffs:
  • Paul Clapham
  • Liutauras Vilda
  • Devaka Cooray
Saloon Keepers:
  • Tim Holloway
  • Roland Mueller
Bartenders:

Retrieve value from a DateField

 
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Ranch Hand
Posts: 331
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Here's some basic code that shows how to use a Calendar object to format and print a date:
 
We can fix it! We just need some baling wire, some WD-40, a bit of duct tape and this tiny ad:
Smokeless wood heat with a rocket mass heater
https://woodheat.net
reply
    Bookmark Topic Watch Topic
  • New Topic