?
Solved

Inserting the date

Posted on 2003-03-19
5
Medium Priority
?
211 Views
Last Modified: 2010-03-31
Hi,

Could anyone tell me how to insert the todays date into a textfield when a button is pressed.

Thanks
0
Comment
Question by:rebel_vb
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
5 Comments
 
LVL 3

Accepted Solution

by:
allahabad earned 100 total points
ID: 8168746
// import these two classes into Java file
import  java.util.Date;
import java.text.SimpleDateFormat;

   yourTextField  = new TextField(15);
   yourButton = new Button("Put Date");
   yourButton.addActionListener(this);
   
// this is the method to put Date into text field
public void actionPerformed(ActionEvent e) {
         
    if (e.getSource() == yourButton){
         SimpleDateFormat formatter = new SimpleDateFormat("mm/dd/yyyy");
         Date currentDate = new Date();
         yourTextField.setText(formatter.format(currentDate););
    }  
}
0
 
LVL 2

Expert Comment

by:glottis
ID: 8171955
instead of Date class you can also use Calendar class.

like this:

Calendar cal = Calendar.getInstance();
formatter.format(cal.getTime());

I say this because nearly all methods of Date class are deprecated.
0
 

Expert Comment

by:CleanupPing
ID: 9058593
rebel_vb:
This old question needs to be finalized -- accept an answer, split points, or get a refund.  For information on your options, please click here-> http:/help/closing.jsp#1 
EXPERTS:
Post your closing recommendations!  No comment means you don't care.
0
 
LVL 15

Expert Comment

by:jimmack
ID: 9727275
No comment has been added lately, so it's time to clean up this TA.
I will leave a recommendation in the Cleanup topic area that this question is:

Accept allahabad's comment as answer.

Please leave any comments here within the next seven days.

PLEASE DO NOT ACCEPT THIS COMMENT AS AN ANSWER!

jimmack
EE Cleanup Volunteer
0

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In this post we will learn how to connect and configure Android Device (Smartphone etc.) with Android Studio. After that we will run a simple Hello World Program.
Basic understanding on "OO- Object Orientation" is needed for designing a logical solution to solve a problem. Basic OOAD is a prerequisite for a coder to ensure that they follow the basic design of OO. This would help developers to understand the b…
Viewers will learn about the different types of variables in Java and how to declare them. Decide the type of variable desired: Put the keyword corresponding to the type of variable in front of the variable name: Use the equal sign to assign a v…
Viewers will learn about the regular for loop in Java and how to use it. Definition: Break the for loop down into 3 parts: Syntax when using for loops: Example using a for loop:
Suggested Courses
Course of the Month8 days, 18 hours left to enroll

764 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question