Here you can find the source of durationToFormattedString(final Duration duration)
Parameter | Description |
---|---|
duration | duration, which will be converted into a formatted String |
public static String durationToFormattedString(final Duration duration)
//package com.java2s; /**/*w ww .j av a 2s. c om*/ * Copyright (c) 2015 Bosch Software Innovations GmbH and others. * * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at * http://www.eclipse.org/legal/epl-v10.html */ import java.time.Duration; import java.time.LocalTime; import java.time.format.DateTimeFormatter; public class Main { /** * Format of the String expected in configuration file and in the database. */ public static final String DURATION_FORMAT = "HH:mm:ss"; /** * Converts a Duration into a formatted String * * @param duration * duration, which will be converted into a formatted String * @return String in the duration format, specified at * {@link #DURATION_FORMAT} */ public static String durationToFormattedString(final Duration duration) { if (duration == null) { return null; } return LocalTime.ofNanoOfDay(duration.toNanos()).format(DateTimeFormatter.ofPattern(DURATION_FORMAT)); } }