gpt4 book ai didi

java - 使用公历作为时间戳

转载 作者:行者123 更新时间:2023-11-30 02:50:16 26 4
gpt4 key购买 nike

我有一个包含电子邮件类的项目,如下所示

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/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com