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

Date method

 
Ranch Hand
Posts: 123
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
What date method would I use to set the current date in a textfield?
 
Bartender
Posts: 1844
Eclipse IDE Ruby Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I'm uncertain what you mean...I can infer many questions from your question.
To get the current date, just do new java.util.Date(). (or java.util.Calendar.getInstance())
For formatting the date, look at the java.text.SimpleDateFormat class. It probably will do what you need. The methods of interest are format (Date -> String) and parse (String -> Date).
To set the information in the text field, use the setText(String) method.
 
Ranch Hand
Posts: 3061
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You can easily use the Date class to get the current date. Then use the Date.toString() method to convert it to a String to add to your TextField object.
 
Candy Bortniker
Ranch Hand
Posts: 123
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I am using:

I get the date with the time but I only want the date, not the time. How do I do that?
 
Joel McNary
Bartender
Posts: 1844
Eclipse IDE Ruby Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Candy Bortniker:
I am using:

I get the date with the time but I only want the date, not the time. How do I do that?


If you are concerned with only displaying the date, use java.text.SimpleDateFormat.

This will format the date
If you don't want your Date object to carry the time at all, you can do this:

but when you display the date you still will have to format it, othersie you will still get the "Wed Apr 16 00:00:00 EDT 2003" (or some such) when you call .toString() on the Date.
 
joke time: What is brown and sticky? ... ... ... A stick! Use it to beat this tiny ad!
The new gardening playing cards kickstarter is now live!
https://www.kickstarter.com/projects/paulwheaton/garden-cards
reply
    Bookmark Topic Watch Topic
  • New Topic