This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan on-line!
See this thread for details.
The moose likes Beginning Java and the fly likes Date method Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Date method" Watch "Date method" New topic
Author

Date method

Candy Bortniker
Ranch Hand

Joined: Mar 17, 2003
Posts: 123
What date method would I use to set the current date in a textfield?
Joel McNary
Bartender

Joined: Aug 20, 2001
Posts: 1817

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.


Piscis Babelis est parvus, flavus, et hiridicus, et est probabiliter insolitissima raritas in toto mundo.
Layne Lund
Ranch Hand

Joined: Dec 06, 2001
Posts: 3061
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.


Java API Documentation
The Java Tutorial
Candy Bortniker
Ranch Hand

Joined: Mar 17, 2003
Posts: 123
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

Joined: Aug 20, 2001
Posts: 1817

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.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Date method
 
Similar Threads
How to manipulate the Date object in yyyy-MM-DD HH:MM:SS format.
Convert a Timestamp to Calander Object
Problem with Date Object
Get time in seconds/mili seconds
Date date = new Date(String str)