/* * Copyright (C) 2014-2015 ULYSSIS VZW * * This file is part of i++. * * i++ is free software: you can redistribute it and/or modify * it under the terms of version 3 of the GNU Affero General Public License * as published by the Free Software Foundation. No other versions apply. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Affero General Public License for more details. * * You should have received a copy of the GNU Affero General Public License * along with this program. If not, see <http://www.gnu.org/licenses/> */ package org.ulyssis.ipp.ui; import java.time.DateTimeException; import java.time.Instant; import java.time.LocalDateTime; import java.time.ZoneId; import java.time.format.DateTimeFormatter; public final class TimeUtils { private TimeUtils() { } public static String formatDateForInstant(Instant instant) { try { LocalDateTime localDate = LocalDateTime.ofInstant(instant, ZoneId.systemDefault()); DateTimeFormatter formatter = DateTimeFormatter.ofPattern("dd MMMM yyyy"); return localDate.format(formatter); } catch (DateTimeException ignored) { return "N/A"; } } public static String formatTimeForInstant(Instant instant) { try { LocalDateTime localTime = LocalDateTime.ofInstant(instant, ZoneId.systemDefault()); DateTimeFormatter formatter = DateTimeFormatter.ofPattern("HH:mm:ss"); return localTime.format(formatter); } catch (DateTimeException ignored) { return "N/A"; } } }