Java_joda-time(1)時間操作(時間,日期)
package com.lius.joda; import org.joda.time.DateTime; import org.joda.time.LocalDate; /** * <p>joda-time (時間&&日期)</p> */ public class jodaTimeTest1 { public static void main(String[] args) { //獲取當前時間 DateTime today = new DateTime(); System.out.println(today.toString("yyyy-MM-dd")); //獲取明天時間 DateTime tomorrow = today.plusDays(1); System.out.println(tomorrow.toString("yyyy-MM-dd")); //獲取當月第一天的時間 DateTime oneDayofMonth = today.withDayOfMonth(1); System.out.println(oneDayofMonth.toString("yyyy-MM-dd")); //獲取當前日期 LocalDate localDate = new LocalDate(); System.out.println(localDate); //獲取3個月後的最後一天 LocalDate otherDate = localDate.plusMonths(3).dayOfMonth().withMaximumValue(); System.out.println(otherDate); //計算2年前第3個月的最後一天的時間 DateTime otherDate2 = today.minusYears(2).monthOfYear().setCopy(3).dayOfMonth().withMaximumValue(); System.out.println(otherDate2.toString("yyyy-MM-dd")); } }