import java.text.SimpleDateFormat;
import java.time.Instant;
import java.time.OffsetDateTime;
import java.time.ZoneOffset;
import java.time.format.DateTimeFormatter;
import java.util.Locale;
import java.util.TimeZone;
public class TestTime {
public static void main(String[] args){
OffsetDateTime jdkTime = Instant.EPOCH.atOffset(ZoneOffset.UTC);
StringBuffer sb = new StringBuffer();
sb.append("; jdkTime=").append(jdkTime.format(DateTimeFormatter.RFC_1123_DATE_TIME)).append("\r\n");
org.joda.time.Instant jodaTime = new org.joda.time.Instant(0);
SimpleDateFormat RFC_ZERO_Format = new SimpleDateFormat("EEE, d MMM yyyy HH:mm:ss 'GMT'", Locale.US);
RFC_ZERO_Format.setTimeZone(TimeZone.getTimeZone("GMT"));
sb.append("; jodaTime=").append(RFC_ZERO_Format.format(jodaTime.getMillis())).append("\r\n");
jdkTime = OffsetDateTime.now().plusSeconds(100);
sb.append("; jdkTime=").append(jdkTime.format(DateTimeFormatter.RFC_1123_DATE_TIME)).append("\r\n");
jodaTime = org.joda.time.Instant.now().plus(org.joda.time.Duration.standardSeconds(100).getMillis());
SimpleDateFormat RFC_Format = new SimpleDateFormat("EEE, d MMM yyyy HH:mm:ss Z", Locale.US);
sb.append("; jodaTime=").append(RFC_Format.format(jodaTime.getMillis())).append("\r\n");
System.out.println(sb.toString());
}
}
执行结果: