本文最后更新于:2021年10月7日 凌晨
概览 :joda-time学习与使用
joda_time 官网:https://www.joda.org/joda-time/index.html
Maven依赖:
1 2 3 4 5 <dependency > <groupId > joda-time</groupId > <artifactId > joda-time</artifactId > <version > 2.10.10</version > </dependency >
对应包名:``org.joda.time.
DateTime类 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 DateTime dateTime = new DateTime(); System.out.println(dateTime); DateTime dateTime1 = new DateTime(2000 ,11 ,21 ,7 ,10 ,25 ); System.out.println(dateTime1); DateTime changeDayDate = dateTime1.withDayOfMonth(1 ); System.out.println(changeDayDate); changeDayDate = dateTime1.plusDays(3 ).minusMonths(2 ); System.out.println(changeDayDate); System.out.println(dateTime1.getHourOfDay()); System.out.println(dateTime1.monthOfYear().getAsText()); System.out.println(dateTime1.monthOfYear().getAsText(Locale.ENGLISH)); DateTime now = new DateTime(); System.out.println(now.dayOfWeek().roundFloorCopy()); System.out.println(now.dayOfWeek().roundCeilingCopy()); System.out.println(dateTime1.year().getAsText() + ":" + dateTime1.year().isLeap()); System.out.println(now.year().getAsText() + ":" + now.year().isLeap());
格式化 1 2 3 DateTimeFormatter fmt = DateTimeFormat.forPattern("yyyy MM dd - HH:mm:ss" ); System.out.println(fmt.print(new DateTime()));