Osaid Az
Osaid Az

Reputation: 3

how can I show date in GUI text field?

I'm trying to show date in a text field this is what I did

java.util.Date date=new java.util.Date();
this.DateObject.setText(date);

But it shows error...

Upvotes: 0

Views: 5982

Answers (2)

Dhinakar
Dhinakar

Reputation: 4151

Try below code.

        Date now = new Date();
        //Set date format as you want
        SimpleDateFormat sf = new SimpleDateFormat("dd-MM-yy"); 
        this.DateObject.setText(sf.format(now));

Upvotes: 10

mtk
mtk

Reputation: 13709

You might need to do a toString on it as

this.DateObject.setText(date.toString());

Upvotes: 1

Related Questions