• Post Reply Bookmark Topic Watch Topic
  • New Topic

Setting up a date in netbeans

 
Jamie Wool
Ranch Hand
Posts: 49
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Im trying to work out how to display the system date at the bottom of a jTextField in a jToolBar. Basically i managed to get this code working

jTextField2.setText(new java.util.Date().toString());

but it doens't allow me to edit the format, i pretty much want "16 January 2004". I also noticed that it doesn't refresh, so if i include the time field it's not much use.

Cheers
 
Anand Karia
Ranch Hand
Posts: 156
Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Here is something for you.

import java.text.SimpleDateFormat;

Declare the following
public SimpleDateFormat f = new SimpleDateFormat("dd-MMM-yyyy");

Write this code onto anything event you like.
lblDate.setText(f.format(new Date()));

Hope this would help you out.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!