Converts our own relative time format to a LocalDateTime object. - Java java.time

Java examples for java.time:LocalDateTime

Description

Converts our own relative time format to a LocalDateTime object.

Demo Code


//package com.java2s;

import java.time.*;

public class Main {
    /**//from  w w  w  . j  a v  a2  s .c o m
     * Converts our own relative time format to a LocalDateTime object.
     * The date part is the current date.
     *
     * @param relativeTime Seconds after midnight.
     * @return A LocalDateTime for today, at the given time.
     */
    public static LocalDateTime convertRelativeTime(int relativeTime) {
        return LocalDateTime.of(LocalDate.now(),
                LocalTime.ofSecondOfDay(relativeTime));
        // int hours = relativeTime/3600;
        // relativeTime -= (hours * 3600);
        // int minutes = relativeTime/60;
        // relativeTime -= (minutes * 60);
        // int seconds = relativeTime;

        // return LocalDate.now().atTime(hours, minutes, seconds);
    }
}

Related Tutorials