To get the current time 10 minutes ago using LocalDateTime in Java, you can use the minusMinutes() method. Here's an example:

import java.time.LocalDateTime;

public class Main {
    public static void main(String[] args) {
        LocalDateTime currentTime = LocalDateTime.now();
        LocalDateTime time10MinutesAgo = currentTime.minusMinutes(10);
        System.out.println("Current Time: " + currentTime);
        System.out.println("10 Minutes Ago: " + time10MinutesAgo);
    }
}

Output:

Current Time: 2022-10-12T15:30:45.123456789
10 Minutes Ago: 2022-10-12T15:20:45.123456789

In the above example, LocalDateTime.now() is used to get the current time. Then, minusMinutes(10) is called on the currentTime object to subtract 10 minutes and get the time 10 minutes ago

java localdatetime 10分钟前

原文地址: https://www.cveoy.top/t/topic/hFDg 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录