非常简单的问题:
我正在尝试在此代码的下一行打印出时间戳。它正在打印到jTextArea。我现在如何获得代码由于某种原因不起作用:
try {
Calendar calendar = Calendar.getInstance();
Timestamp currentTimestamp = new java.sql.Timestamp(calendar.getTime().getTime());
DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
DocumentBuilder docBuilder = factory.newDocumentBuilder();
Document doc = docBuilder.newDocument();
Element root = doc.createElement("message");
doc.appendChild(root);
root.appendChild(doc.createTextNode(userName.getText() + ": " + msgText.getText() + "\n" + "sent at " + currentTimestamp));
TransformerFactory fact = TransformerFactory.newInstance();
Transformer trans = fact.newTransformer();
DOMSource source = new DOMSource(doc);
StreamResult sResult = new StreamResult(out);
trans.transform(source, sResult);
msgText.setText("");
out.println("\n");
out.flush();
} catch (Exception e) {
}
...谢谢
答案 0 :(得分:0)
GUYS你是对的,这是创建转换为XML的文档。我想在将xml再次转换为字符串后,我只会在另一边添加时间戳