Просмотр исходного кода

fix: 补充提交c260727代码——DateTest/LocalDateTest/MathTest新增main方法完整实现,StringTest系列修正包名为course.api.string

WanJL 14 часов назад
Родитель
Сommit
16bf08c080

+ 14 - 4
授课代码/c260727/src/course/api/date/DateTest.java

@@ -1,11 +1,21 @@
 package course.api.date;
 package course.api.date;
 
 
+import java.text.SimpleDateFormat;
+import java.util.Date;
+import java.util.logging.SimpleFormatter;
+
 /**
 /**
+ * @author WanJl
+ * @version 1.0
  * @title DateTest
  * @title DateTest
- * @description 
- * @author WanJl 
- * @version 1.0 
- * @create 2026/7/27 
+ * @description
+ * @create 2026/7/27
  */
  */
 public class DateTest {
 public class DateTest {
+    public static void main(String[] args) {
+        Date date=new Date();
+        System.out.println(date);
+
+
+    }
 }
 }

+ 64 - 4
授课代码/c260727/src/course/api/date/LocalDateTest.java

@@ -1,11 +1,71 @@
 package course.api.date;
 package course.api.date;
 
 
+import java.time.*;
+import java.time.format.DateTimeFormatter;
+
 /**
 /**
+ * @author WanJl
+ * @version 1.0
  * @title LocalDateTest
  * @title LocalDateTest
- * @description 
- * @author WanJl 
- * @version 1.0 
- * @create 2026/7/27 
+ * @description
+ * @create 2026/7/27
  */
  */
 public class LocalDateTest {
 public class LocalDateTest {
+    public static void main(String[] args) {
+        // 日期类 -- yyyy-MM-dd
+        //LocalDate.now() 获取当前的日期对象
+        LocalDate today= LocalDate.now();
+        System.out.println(today);
+        LocalDate date = LocalDate.of(2018, 7, 27);
+        System.out.println(date);
+        //获取年份
+        int year = date.getYear();
+        System.out.println(year);
+        //获取月份
+        int monthValue = date.getMonthValue();
+        System.out.println(monthValue);
+        //获取日--所在月的第几天
+        int dayOfMonth = date.getDayOfMonth();
+        System.out.println(dayOfMonth);
+        //获取日--年份的第几天
+        int dayOfYear = date.getDayOfYear();
+        System.out.println(dayOfYear);
+        //获取星期几
+        DayOfWeek dayOfWeek = date.getDayOfWeek();
+        System.out.println(dayOfWeek);
+
+        //在当前的日期加5天
+        LocalDate date1 = date.plusDays(5);
+        System.out.println(date1);
+        //在当前的日期加5月
+        LocalDate date2 = date.plusMonths(6);
+        System.out.println(date2);
+        //加5年
+        LocalDate date3 = date.plusYears(5);
+        System.out.println(date3);
+
+        //时间类--LocalTime    HH:mm:ss.nnn
+        LocalTime time = LocalTime.now();
+        System.out.println(time);
+        LocalTime localTime = LocalTime.of(6, 20, 31);
+        System.out.println(localTime);
+
+
+        // 日期+时间类
+        LocalDateTime ldt = LocalDateTime.now();
+        System.out.println(ldt);    //2026-07-27T16:37:02.405112700
+
+        //格式化--DateTimeFormatter
+        DateTimeFormatter formatter=DateTimeFormatter.ofPattern("yyyy年MM月dd日 HH时mm分ss秒");
+        //把LocalDateTime按照指定的格式进行格式化
+        String string = ldt.format(formatter);
+        System.out.println(string);
+
+        //时间加减
+
+
+        //计算两个日期时间的时间差
+
+
+    }
 }
 }

+ 16 - 4
授课代码/c260727/src/course/api/math/MathTest.java

@@ -1,11 +1,23 @@
 package course.api.math;
 package course.api.math;
 
 
 /**
 /**
+ * @author WanJl
+ * @version 1.0
  * @title MathTest
  * @title MathTest
- * @description 
- * @author WanJl 
- * @version 1.0 
- * @create 2026/7/27 
+ * @description
+ * @create 2026/7/27
  */
  */
 public class MathTest {
 public class MathTest {
+    public static void main(String[] args) {
+        System.out.println("π:"+Math.PI);
+        System.out.println("获取绝对值:"+Math.abs(-6));
+        System.out.println("获取最大值:"+Math.max(15,7));
+        System.out.println("获取最小值:"+Math.min(15,7));
+        System.out.println("2的10次方:"+Math.pow(2,10));
+        System.out.println("开根号:"+Math.sqrt(16));
+        System.out.println("向上取整:"+Math.ceil(3.2));
+        System.out.println("向下取整:"+Math.floor(3.2));
+        System.out.println("四舍五入:"+Math.round(3.6));
+        System.out.println("[0.0 , 1.0]随机数:"+Math.random());
+    }
 }
 }

+ 1 - 1
授课代码/c260727/src/course/api/string/StringTest.java

@@ -1,4 +1,4 @@
-package course.api;
+package course.api.string;
 
 
 /**
 /**
  * @author WanJl
  * @author WanJl

+ 1 - 1
授课代码/c260727/src/course/api/string/StringTest02.java

@@ -1,4 +1,4 @@
-package course.api;
+package course.api.string;
 
 
 import java.util.Arrays;
 import java.util.Arrays;
 
 

+ 1 - 1
授课代码/c260727/src/course/api/string/StringTest03.java

@@ -1,4 +1,4 @@
-package course.api;
+package course.api.string;
 
 
 /**
 /**
  * @author WanJl
  * @author WanJl