且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

将日期加载到JTextField中

更新时间:2023-12-02 18:24:40

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

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

  1. 使用Date()获取当前日期时间

  1. get current date time with Date()

//get current date time with Date()
   Date date = new Date();
   System.out.println(dateFormat.format(date));
   jTextField3.setText(dateFormat.format(date));

  • 使用Calendar()获取当前日期时间

  • get current date time with Calendar()

    //get current date time with Calendar()
       Calendar cal = Calendar.getInstance();
       jTextField3.setText(dateFormat.format(cal.getTime()));