Java 如何在jframe标题栏上显示当前日期?

Java 如何在jframe标题栏上显示当前日期?,java,swing,jframe,titlebar,Java,Swing,Jframe,Titlebar,我寻找解决办法,但没有找到。我想在jframe标题栏上显示当前日期。我知道如何使用java获取当前日期,但我需要在标题栏上显示它。有人能帮我吗 提前感谢。要获取当前日期,请使用java.util.date 要格式化日期,请使用java.text.simpleDataFormat 为JFRame设置标题> JFrame jFrame= new JFrame("title"); 或 所以解决办法是, DateFormat dateFormat = new SimpleDateFormat("yyy

我寻找解决办法,但没有找到。我想在jframe标题栏上显示当前日期。我知道如何使用java获取当前日期,但我需要在标题栏上显示它。有人能帮我吗


提前感谢。

要获取当前日期,请使用
java.util.date

要格式化日期,请使用
java.text.simpleDataFormat

为JFRame设置标题>

JFrame jFrame= new JFrame("title");

所以解决办法是,

DateFormat dateFormat = new SimpleDateFormat("yyyy/MM/dd HH:mm:ss");
Date date = new Date();

JFrame jFrame= new JFrame("Current Date: "+dateFormat.format(date));

or 

jFrame.setTitle("Current Date"+dateFormat.format(date));

要获取当前日期,请使用
java.util.date

要格式化日期,请使用
java.text.simpleDataFormat

为JFRame设置标题>

JFrame jFrame= new JFrame("title");

所以解决办法是,

DateFormat dateFormat = new SimpleDateFormat("yyyy/MM/dd HH:mm:ss");
Date date = new Date();

JFrame jFrame= new JFrame("Current Date: "+dateFormat.format(date));

or 

jFrame.setTitle("Current Date"+dateFormat.format(date));
答案是正确的

用Joda时间定位 如果需要日期的本地化格式,请使用库

或者,如果要将java.util.Date转换为Joda Time

DateTime dateTime = new DateTime( date, DateTimeZone.forID( "America/Montreal" ) );
使用本地化格式生成日期时间值的字符串表示形式。使用具有Joda时间的对象

答案是正确的

用Joda时间定位 如果需要日期的本地化格式,请使用库

或者,如果要将java.util.Date转换为Joda Time

DateTime dateTime = new DateTime( date, DateTimeZone.forID( "America/Montreal" ) );
使用本地化格式生成日期时间值的字符串表示形式。使用具有Joda时间的对象


我知道如何使用java获取当前日期。我的问题是我需要在标题栏上显示它。@Pappu我不相信您“搜索了解决方案”并且找不到更改JFrame标题的方法。@DSquare我知道如何更改它,但只使用netbeans中的“属性”选项。我知道如何使用java获取当前日期。我的问题是我需要在标题栏上显示它。@Pappu我不相信您“搜索了解决方案”并且找不到更改JFrame标题的方法。@DSquare我知道如何更改它,但只使用netbeans中的“属性”选项。我在发布它之前得到了解决方案:)我在发布它之前得到了解决方案:)