·

看看 JDK 8 的 time 处理多舒服

import java.time.Duration;
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;

public class CheckWhatDoing {
    public static void main(String[] args) {
        String str = "1990-01-01 00:00:00";
        LocalDateTime startDay = LocalDateTime.parse(str, DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss"));
        LocalDateTime now = LocalDateTime.now();
        int days = (int) Duration.between(startDay, now).toDays();
        System.out.println(days);
        if ((days % 5) < 3) {
            System.out.println("正在打渔");
        } else {
            System.out.println("正在晒网");
        }
    }
Replies
1

学到了学到了,谢谢大家。