下面列出了java.time.OffsetDateTime#getSecond ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
void initImageCreationTime(OffsetDateTime offsetDateTime) {
// Check for incoming arguments
if (offsetDateTime != null) {
// set values that make up Standard/Document/ImageCreationTime
creation_time_present = true;
creation_time_year = offsetDateTime.getYear();
creation_time_month = offsetDateTime.getMonthValue();
creation_time_day = offsetDateTime.getDayOfMonth();
creation_time_hour = offsetDateTime.getHour();
creation_time_minute = offsetDateTime.getMinute();
creation_time_second = offsetDateTime.getSecond();
creation_time_offset = offsetDateTime.getOffset();
}
}
public static int writeGeneralizedTime(Date time, byte[] out, int offset) {
OffsetDateTime offsetTime = time.toInstant().atOffset(ZoneOffset.UTC);
int idx = offset;
out[idx++] = 0x18;
out[idx++] = 15;
// yyyyMMddhhmmssZ
// year
int year = offsetTime.getYear();
out[idx++] = (byte) (0x30 + year / 1000);
out[idx++] = (byte) (0x30 + year / 100 % 10);
out[idx++] = (byte) (0x30 + year / 10 % 10);
out[idx++] = (byte) (0x30 + year % 10);
// month
int month = offsetTime.getMonthValue();
out[idx++] = (byte) (0x30 + month / 10);
out[idx++] = (byte) (0x30 + month % 10);
// day
int day = offsetTime.getDayOfMonth();
out[idx++] = (byte) (0x30 + day / 10);
out[idx++] = (byte) (0x30 + day % 10);
// hour
int hour = offsetTime.getHour();
out[idx++] = (byte) (0x30 + hour / 10);
out[idx++] = (byte) (0x30 + hour % 10);
// minute
int minute = offsetTime.getMinute();
out[idx++] = (byte) (0x30 + minute / 10);
out[idx++] = (byte) (0x30 + minute % 10);
// second
int second = offsetTime.getSecond();
out[idx++] = (byte) (0x30 + second / 10);
out[idx++] = (byte) (0x30 + second % 10);
out[idx++] = 'Z';
return idx - offset;
}
private boolean timeEmpty(OffsetDateTime dateTime) {
return dateTime.getHour() == 0
&& dateTime.getMinute() == 0
&& dateTime.getSecond() == 0
&& dateTime.getNano() == 0;
}
private void addMinute(OffsetDateTime dateTime, StringBuilder builder) {
if (!(dateTime.getMinute() == 0 && dateTime.getSecond() == 0)) {
builder.append(":mm");
}
}
private void addSecond(OffsetDateTime dateTime, StringBuilder builder) {
if (dateTime.getSecond() != 0) {
builder.append(":ss");
}
}