0

Default timezone for notes created in onenote is UTC but when I create new notebook in onenote and fetch default note using onenote api, we see GMT timezone for that note.

keshav
  • 734
  • 6
  • 19

1 Answers1

0

Here is the way I do:

Eg. For the createdTime attribute of any element

    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;
        }
    }
lvr123
  • 524
  • 6
  • 24