private void log(String log) {
Date date = new Date();
/**年-月-日**/ /**时:分:秒**/
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
String dateStr = sdf.format(date);/**dateStr当前日期**/
JTextPane txtLog = serverFrame.serverInfoPanel.txtLog;
String oldLog = txtLog.getText();
txtLog.setText(oldLog + "\n" + dateStr + " " + log);
format它通过格式操作使任意类型的数据转换成一个字符串
本文介绍了一种在Java中记录日志的方法。该方法通过创建一个SimpleDateFormat对象来格式化当前日期和时间,并将带有时间戳的日志消息追加到JTextPane组件中。这种方法便于在应用程序中实时查看和管理日志。
198

被折叠的 条评论
为什么被折叠?



