you can use the Gregorian Calendar class to create an instance of that class and then extract the data that you need from that object
http://docs.oracle.com/javase/6/docs...nCalendar.html
once that is done, you should probably create a JLabel and set the text as the date and time that you want. You will then add it to a JPanel inside your JFrame.
Something like this:
-
-
class JFrameDate{
-
public static final String DATE_FORMAT_NOW = "yyyy-MM-dd HH:mm:ss";
-
-
//this method gets the date and time now. you can modify the
-
//date format to not show the time
-
-
public static String timeNow() {
-
Calendar cal = Calendar.getInstance();
-
SimpleDateFormat sdf = new SimpleDateFormat(DATE_FORMAT_NOW);
-
return sdf.format(cal.getTime());
-
}
-
-
public static void main(String [] args){
-
JFrame myFrame = new JFrame("Show Date");
-
myFrame.setVisible(true);
-
-
JPanel myPanel = new JPanel();
-
-
JLabel dateTime = new JLabel();
-
dateTime.setText(JFrameDate.timeNow());
-
-
myPanel.add(dateTime);
-
-
myFrame.add(myPanel);
-
}
-
}
-
i have not tested this code, but the idea is straight forward. You will have to adjust your JFrame and JPanels to the layout, size and display location you want, but i think this is a good starting point