在onenote中创建的备注的默认时区是UTC,但是当我在onenote中创建新笔记本并使用onenote api获取默认备注时,我们会看到该备注的GMT时区。
答案 0 :(得分:0)
这是我的方式:
EG。对于任何元素的createdTime属性
createdTime = getAsLocalDateTime(data, "createdTime");
/**
* Returns the attribute in a LocalDateTime object. Expects a string formatted as a {@link java.time.format.DateTimeFormatter#ISO_INSTANT}.
* Returns null if no such attribute or if the data is wrongly formatted.
*
* @param data
* @param attribut
*
* @return
*/
public static LocalDateTime getAsLocalDateTime(JsonObject data, String attribut) {
final JsonPrimitive primitive = data.getAsJsonPrimitive(attribut);
if (primitive == null)
return null;
final String tmsp = primitive.getAsString().substring(0, 19) + "Z"; // I cut OneNote timestamps that are too long in the nanoseconds
try {
// We read GMT, we've got to get back to local time zone
final ZonedDateTime d = ZonedDateTime.parse(tmsp, DATE_FORMAT);
final LocalDateTime ld = d.withZoneSameInstant(ZoneId.systemDefault()).toLocalDateTime();
// System.out.println("# "+tmsp+" # "+d.toString()+" # "+ld.toString());
return ld;
} catch (DateTimeParseException e) {
logger.error("while retrieving date from \""+tmsp+"\"",e);
return null;
}
}