以邮件格式打印时间戳

时间:2017-01-19 08:07:50

标签: java timestamp

好的我正在尝试打印一个jtable,我想在页脚消息上打印时间日期,我怎样才能让它成为真正的

private void jButton6ActionPerformed(java.awt.event.ActionEvent evt)
 {                                         
     MessageFormat header = new MessageFormat("ΟΜΑΔΕΣ ΚΛΑΣΕΙΣ");
     String timeStamp = new SimpleDateFormat("yyyyMMddHHmmss").format(Calendar.getInstance().getTime());
   //MessageFormat footer = new MessageFormat('SimpleDateFormat);
     MessageFormat footer = new 
     MessageFormat("SimpleDateFormat{yyyyMMddHHmmss,String}");
      try
       {
          jTable_Userss.print(JTable.PrintMode.FIT_WIDTH, header, footer);  
       }
      catch (java.awt.print.PrinterException e)
       {
           System.err.format("Cannot print %$%n",e.getMessage());
       }

  } 

2 个答案:

答案 0 :(得分:0)

经过一些测试后我找到了答案

MessageFormat header = new MessageFormat("ΟΜΑΔΕΣ ΚΛΑΣΕΙΣ");
         //String TimeStamp = new SimpleDateFormat("yyyyMMddHHmmss").format(Calendar.getInstance().getTime());

           Calendar cal = new GregorianCalendar();
               int month =cal.get(Calendar.MONTH);
               int year =cal.get(Calendar.YEAR);
               int day =cal.get(Calendar.DAY_OF_MONTH);

            MessageFormat footer = new MessageFormat("Date "+year+"/"+(month+1)+"/"+day);
           // MessageFormat footer = new MessageFormat("Page{0,number,integer},"  );
            try {
                jTable_Userss.print(JTable.PrintMode.FIT_WIDTH, header, footer);


            } catch (java.awt.print.PrinterException e){
                System.err.format("Cannot print %$%n",e.getMessage());
            }

        }                                        

答案 1 :(得分:0)

MessageFormat header = new MessageFormat("Report");

Calendar cal = new GregorianCalendar();

int month =cal.get(Calendar.MONTH);
int year =cal.get(Calendar.YEAR);
int day =cal.get(Calendar.DAY_OF_MONTH);

MessageFormat footer = new MessageFormat("Date "+year+"/"+(month+1)+"/"+day+"Page{0,number,integer});

try {
    jTable_Userss.print(JTable.PrintMode.FIT_WIDTH, header, footer);
} catch (java.awt.print.PrinterException e){
    System.err.format("Cannot print %$%n",e.getMessage());
}