我有一个包含电子邮件类的项目,如下所示
import java.util.Calendar;
import java.util.GregorianCalendar;
public class Email /*implements serializbale*/{
private String to;
private String cc;
private String bcc;
private String subject;
private String body;
private GregorianCalendar timestamp; //time that email was created
GregorianCalendar cal = new GregorianCalendar();
public Email(String to, String cc, String bcc, String subject, String body, GregorianCalendar timestamp) {
super();
this.to = to;
this.cc = cc;
this.bcc = bcc;
this.subject = subject;
this.body = body;
this.timestamp = timestamp;
我想我什至不需要在构造函数中使用时间戳参数。每当承包商被要求提供电子邮件对象时,我只想将时间戳设置为当前时间。有人可以解释一下如何做到这一点吗?
最佳答案
您可以使用以下方法来获取当前时间
LocalDateTime currentTime;
public Email(String to, String cc, String bcc, String subject, String body) {
super();
this.to = to;
this.cc = cc;
this.bcc = bcc;
this.subject = subject;
this.body = body;
this.currentTime = LocalDateTime.now();
关于java - 使用公历作为时间戳,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38908025/