集册 Java实例教程 调整日期和时间

调整日期和时间

欢马劈雪     最近更新时间:2020-01-02 10:19:05

584
提示:您可在线编辑运行本教程的实例 - 运行实例,去试试!
调整日期和时间

import java.time.DayOfWeek;

import java.time.LocalDate;

import java.time.temporal.TemporalAdjuster;

import java.time.temporal.TemporalAdjusters;//n o w    j a v a  . c o m 提 供


public class Main {

  public static void main(String[] args) {

    LocalDate today = LocalDate.now();

    System.out.println("Today: " + today);


    // Use a DateAdjuster to adjust today's date to the next Monday

    LocalDate nextMonday = today.with(TemporalAdjusters.next(DayOfWeek.MONDAY));

    System.out.println("Next Monday: " + nextMonday);


    // Use a DateAdjuster to adjust today's date to the last day of month// 来自 N o  w  J a v a . c o m - 时  代  Java

    LocalDate lastDayOfMonth = today.with(TemporalAdjusters.lastDayOfMonth());

    System.out.println("Last day of month: " + lastDayOfMonth);


    // Create an adjuster that retruns a date after 3 months and 2 days

    TemporalAdjuster adjuster = TemporalAdjusters.ofDateAdjust
展开阅读全文