使用公历作为时间戳

using gregorian calendar as a time stamp

我有一个项目,邮箱class,如下图

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();