2 * Copyright (c) 2010-2023 Contributors to the openHAB project
4 * See the NOTICE file(s) distributed with this work for additional
7 * This program and the accompanying materials are made available under the
8 * terms of the Eclipse Public License 2.0 which is available at
9 * http://www.eclipse.org/legal/epl-2.0
11 * SPDX-License-Identifier: EPL-2.0
13 package org.openhab.binding.luftdateninfo.internal.utils;
15 import java.time.LocalDateTime;
16 import java.time.format.DateTimeFormatter;
17 import java.time.format.DateTimeParseException;
18 import java.util.Locale;
20 import org.eclipse.jdt.annotation.NonNullByDefault;
21 import org.eclipse.jdt.annotation.Nullable;
22 import org.slf4j.Logger;
23 import org.slf4j.LoggerFactory;
26 * The {@link DateTimeUtils} class provides helpers for converting Dates and Times.
28 * @author Bernd Weymann - Initial contribution
31 public class DateTimeUtils {
32 public static final DateTimeFormatter DTF = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss", Locale.ENGLISH);
33 private static final Logger LOGGER = LoggerFactory.getLogger(DateTimeUtils.class);
35 public static synchronized @Nullable LocalDateTime toDate(String dateTime) {
37 return LocalDateTime.from(DTF.parse(dateTime));
39 } catch (DateTimeParseException e) {
40 LOGGER.debug("Unable to parse date {}", dateTime);