十、常用API(二)

一、 Object & Objects

1.1Object

  • Object类概述

    • Object 是类层次结构的根,每个类都可以将 Object 作为超类。所有类都直接或者间接的继承自该类,换句话说,该类所具备的方法,所有类都会有一份
    • 还记得在继承中,为什么默认调用父类的无参构造吗?一部分原因是因为Object中只有无参构造
  • 查看方法源码的方式

    • 选中方法,按下Ctrl + B
1.1.1 Object类的toString方法
  • 源码分析图

在这里插入图片描述

  • 说明

    • 即我们在打印一个对象时,默认返回这个对象的toString()方法,若不重写,则默认使用其父类Object类中的toString()方法:全类名@对象地址值
    • 如果我们希望其打印其他有用的信息时,则需要重写toString()方法
  • 重写toString方法的方式

    • Alt + Insert 选择toString
      1. 在类的空白区域,右键 -> Generate -> 选择toString
  • toString方法的作用:

    • 以良好的格式,更方便的展示对象中的属性值
  • 示例代码:

package com.xu.domain;

public class Student {

    private String name;
    private int age;

    public Student() {
    }

    public Student(String name, int age) {
        this.name = name;
        this.age = age;
    }

    public String getName() {
        return name;
    }


    public int getAge() {
        return age;
    }

    public void setName(String name) {
        this.name = name;
    }

    public void setAge(int age) {
        this.age = age;
    }

    @Override
    public String toString() {
        return "Student{" +
                "name='" + name + '\'' +
                ", age=" + age +
                '}';
    }
}

package com.xu.Test;

import com.xu.domain.Student;

public class Test01 {
    public static void main(String[] args) {
        Student stu = new Student("张三", 20);
        System.out.println(stu);
        System.out.println(stu.toString());
    }

}
// 运行结果
// Student{name='张三', age=20}
// Student{name='张三', age=20}
1.1.2 Object类的equals方法
  • equals方法的作用

    • 用于对象之间的比较,返回true和false的结果。其底层也是通过==比较地址值。
    • 举例:s1.equals(s2); s1和s2是两个对象
  • 重写equals方法的场景

    • 不希望比较对象的地址值,想要比较对象属性值的时候。
  • 重写equals方法的方式

    • alt + insert 选择equals() and hashCode()IntelliJ Default使用默认的模板,一路nextfinish即可
    • 在类的空白区域,右键 -> Generate -> 选择equals() and hashCode(),后面的同上。
package com.xu.domain;

public class Student {

    private String name;
    private int age;

    public Student() {
    }

    public Student(String name, int age) {
        this.name = name;
        this.age = age;
    }

    public String getName() {
        return name;
    }


    public int getAge() {
        return age;
    }

    public void setName(String name) {
        this.name = name;
    }

    public void setAge(int age) {
        this.age = age;
    }

    @Override
    public String toString() {
        return "Student{" +
                "name='" + name + '\'' +
                ", age=" + age +
                '}';
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (o == null || getClass() != o.getClass()) return false;

        Student student = (Student) o;

        if (age != student.age) return false;
        return name != null ? name.equals(student.name) : student.name == null;
    }

}
package com.xu.Test;

import com.xu.domain.Student;

public class Test01 {
    public static void main(String[] args) {
        Student stu = new Student("张三", 20);
        Student stu1 = new Student("李四", 20);
        Student stu2 = new Student("张三", 20);

        System.out.println(stu.equals(stu1));  // false
        System.out.println(stu.equals(stu2));  // true
    }

}
1.1.3 一则面试题
public class Demo02 {
    public static void main(String[] args) {
        // 看程序,分析结果
        String s = "abc";
        StringBuilder sb = new StringBuilder("abc");
        s.equals(sb);
        sb.equals(s);

        //1.此时调用的是String类中的equals方法.
        //保证参数也是字符串,否则不会比较属性值而直接返回false
        System.out.println(s.equals(sb)); // false

        //StringBuilder类中是没有重写equals方法,用的就是Object类中的.
        System.out.println(sb.equals(s)); // false
        
    }
}
  • String中的equals()源码

在这里插入图片描述

  • StringBuilder中没有重写equals()方法,即使用父类Object类中的equals()方法

在这里插入图片描述

1.2 Objects(注意是objects不是object)

  • 常用方法

    方法名说明
    public static String toString(对象)返回参数中对象的字符串表示形式。
    public static String toString(对象, 默认字符串)返回对象的字符串表示形式。
    public static Boolean isNull(对象)判断对象是否为空
    public static Boolean nonNull(对象)判断对象是否不为空
  • 示例代码

package com.xu.Test;

import com.xu.domain.Student;

import java.util.Objects;

public class Demo03 {
    public static void main(String[] args) {
        Student stu = new Student("张三", 20);
        System.out.println(Objects.toString(stu));  // Student{name='张三', age=20}
        stu = new Student();
        System.out.println(Objects.toString(stu));  // Student{name='null', age=0}

        Student stu1 = new Student();
        System.out.println(Objects.isNull(stu1));  // false
        stu1 = null;
        System.out.println(Objects.isNull(stu1));  // true
        System.out.println(Objects.toString(stu1));  // null
        System.out.println(Objects.toString(stu1, "默认"));  // 默认

    }
}

二、包装类

2.1 基本类型包装类

  • 基本类型包装类的作用:

    • 将基本数据类型封装成对象的好处在于可以在对象中定义更多的功能方法操作该数据
    • 常用的操作之一:用于基本数据类型与字符串之间的转换
  • 基本类型对应的包装类(除IntegerCharacter两个包装类,其余都是基本数据类型将首字母大写)

    基本数据类型包装类
    byteByte
    shortShort
    intInteger
    longLong
    floatFloat
    doubleDouble
    charCharacter
    booleanBoolean

2.2 Integer类

  • Integer类概述

    • 包装一个对象中的原始类型 int 的值
  • Integer类构造方法

    方法名说明
    public Integer(int value)根据 int 值创建 Integer 对象(过时)
    public Integer(String s)根据 String 值创建 Integer 对象(过时)
    public static Integer valueOf(int i)返回表示指定的 int 值的 Integer 实例
    public static Integer valueOf(String s)返回一个保存指定值的 Integer 对象 String
package com.xu.Test;

public class Demo05 {
    public static void main(String[] args) {
        //public Integer(int value):根据 int 值创建 Integer 对象(过时)
        Integer i1 = new Integer(100);
        System.out.println(i1);

        //public Integer(String s):根据 String 值创建 Integer 对象(过时)
        Integer i2 = new Integer("100");
        //Integer i2 = new Integer("abc"); //NumberFormatException
        System.out.println(i2);
        System.out.println("=========");

        //public static Integer valueOf(int i):返回表示指定的 int 值的 Integer 实例
        Integer i3 = Integer.valueOf(100);
        System.out.println(i3);

        //public static Integer valueOf(String s):返回一个保存指定值的Integer对象 String
        Integer i4 = Integer.valueOf("100");
        System.out.println(i4);
    }
}

2.3 自动拆箱和自动装箱☆

  • 自动装箱(JDK1.5及之后推出的特性)
    • 装箱:把基本数据类型转换为对应的包装类类型
    • 自动:Java底层会自动帮助我们调用valueOf()方法
  • 自动拆箱(JDK1.5及之后推出的特性)
    • 拆箱:把包装类类型转换为对应的基本数据类型
public class IntegerDemo {
    public static void main(String[] args) {
        // 自动装箱
        // 把基本数据类型转换为对应的包装类类型
        Integer i1 = 100;  // 将基础数据类型int赋值给引用数据类型Integer

        // 自动拆箱
        // 拆箱:把包装类类型转换为对应的基本数据类型
        int i2 = i1;   // 将引用数据类型Integer赋值给基础数据类型int

        // 自动拆箱后再自动装箱
        i1 += 200;  // i1 = i1 + 200;  i1 + 200为自动拆箱;i1 = 300; 是自动装箱

        Integer i3 = null;  // 当引用类型为null时,无法自动拆箱。
        //i3 += 100;  // java.lang.NullPointerException
        if (i3 != null) {  // 建议每次使用前加上非空判断
            i3 += 100;
        }
    }
}

2.4 int和String类型的相互转换

2.4.1int转换为String
  • 转换方式

    • 方式一:直接在数字后加一个空字符串
    • 方式二:通过String类静态方法valueOf()
public class Demo06 {
    public static void main(String[] args) {
        // int转换为String
        int i = 100;
        // 通过String类静态方法valueOf()
        String s = String.valueOf(i);
        System.out.println(s + 100);
        // 直接在数字后加一个空字符串
        String s2 = i + "";
        System.out.println(s2 + 100);

    }
}
2.4.2 String转换为int
  • 转换方式

    • 方式一:先将字符串数字用Integer.valueOf()转成Integer,再调用Integer.intValue()方法
    • 方式二:通过Integer静态方法Integer.parseInt()进行转换
public class Demo07 {
    public static void main(String[] args) {
        String s = "100";
        // 先将字符串数字转成Integer,再调用valueOf()方法
        Integer i = Integer.valueOf(s);
        int i1 = i.intValue();
        System.out.println(i1 + 100);

        // 通过Integer静态方法parseInt()进行转换
        int i2 = Integer.parseInt(s);
        System.out.println(i2 + 100);
    }
}

2.5 字符串数据排序案例

  • 案例需求:

    • 有一个字符串:“91 27 46 38 50”,请写程序实现最终输出结果是:27 38 46 50 91(将字符串类型先分隔后转换成int数组)
  • Arrays的常用方法

方法名说明
public static String toString(int[] a)返回指定数组的内容的字符串表示形式
public static void sort(int[] a)按照数字顺序排列指定的数组
public static int binarySearch(int[] a, int key)利用二分查找返回指定元素的索引
package com.xu.Test;

import java.util.Arrays;

public class Demo08 {
    public static void main(String[] args) {
        //定义一个字符串
        String s = "91 27 46 38 50";

        //把字符串中的数字数据存储到一个int类型的数组中
        String[] strArray = s.split(" ");
//        for(int i=0; i<strArray.length; i++) {
//            System.out.println(strArray[i]);
//        }

        //定义一个int数组,把 String[] 数组中的每一个元素存储到 int 数组中
        int[] arr = new int[strArray.length];
        for (int i = 0; i < arr.length; i++) {
            arr[i] = Integer.parseInt(strArray[i]);
        }

        //对 int 数组进行排序
        Arrays.sort(arr);

        for (int i = 0; i < arr.length; i++) {
            System.out.print(arr[i] + " ");
        }
    }
}

三、时间类

3.1 Date类

  • 计算机中时间原点

    • 1970年1月1日 00:00:00
  • 时间换算单位

    • 1秒 = 1000毫秒
  • Date类概述

    • Date 代表了一个特定的时间,精确到毫秒
  • Date类构造方法

    方法名说明
    public Date()分配一个 Date对象,并初始化,以便它代表它被分配的时间,精确到毫秒
    public Date(long date)分配一个 Date对象,并将其初始化为表示从标准基准时间起指定的毫秒数
import java.util.Date;

public class Demo01 {
    public static void main(String[] args) {
        Date date = new Date();
        System.out.println(date);  // 当前的时间

        Date date2 = new Date(0L);  // 东八区自动+8h  Thu Jan 01 08:00:00 CST 1970
        long time = 1000*3600;
        Date date3 = new Date(time);  // Thu Jan 01 09:00:00 CST 1970
        System.out.println(date2);
        System.out.println(date3);
    }
}

3.2 Date类常用方法

  • 常用方法

    方法名说明
    public long getTime()获取的是日期对象从1970年1月1日 00:00:00到现在的毫秒值
    public void setTime(long time)设置时间,给的是距离时间原点的毫秒值
  • 示例代码

import java.util.Date;

public class Demo02 {
    public static void main(String[] args) {
        Date date1 = new Date();
        // 获取对象的毫秒值
        long time = date1.getTime();
        System.out.println(time);

        // 设置时间对象的毫秒值
        date1.setTime(0L);
        time = date1.getTime();  
        System.out.println(time);  // 0 时间原点
    }
}

3.3 SimpleDateFormat类

  • SimpleDateFormat类概述

    • ``SimpleDateFormat`是一个具体的类,用于以区域设置敏感的方式格式化解析日期。
  • SimpleDateFormat类构造方法

    方法名说明
    public SimpleDateFormat()构造一个SimpleDateFormat,使用默认模式和日期格式
    public SimpleDateFormat(String pattern)构造一个SimpleDateFormat使用给定的模式和默认的日期格式
  • SimpleDateFormat类的常用方法

    • 格式化(从DateString
      • public final String format(Date date):将日期格式化成日期/时间字符串
    • 解析(从StringDate
      • public Date parse(String source):从给定字符串的开始解析文本以生成日期
  • 示例代码

package com.xu.test;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;

public class Demo03 {
    public static void main(String[] args) throws ParseException {
        // public SimpleDateFormat(String pattern)
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        //格式化:从 Date 到 String
        Date date1 = new Date();
        String s = sdf.format(date1);
        System.out.println(s);

        //从 String 到 Date
        String s1 = "2022-5-14";
        SimpleDateFormat sdf2 = new SimpleDateFormat("yyyy-MM-dd");
        Date date = sdf2.parse(s1);
        System.out.println(date);

    }
}

3.4 时间日期类练习

  • 需求

    秒杀开始时间是2020年11月11日 00:00:00,结束时间是2020年11月11日 00:10:00,用户小贾下单时间是2020年11月11日 00:03:47,用户小皮下单时间是2020年11月11日 00:10:11,判断用户有没有成功参与秒杀活动

  • 实现步骤

    1. 判断下单时间是否在开始到结束的范围内
    2. 把字符串形式的时间变成毫秒值
  • 代码实现

package com.xu.dateapi;

import java.text.ParseException;
import java.text.SimpleDateFormat;

public class Demo04 {
    public static void main(String[] args) throws ParseException {
        //开始时间:2020年11月11日 0:0:0
        //结束时间:2020年11月11日 0:10:0
        String start = "2020年11月11日 0:0:0";
        String end = "2020年11月11日 0:10:0";

        //小贾2020年11月11日 0:03:47
        //小皮2020年11月11日 0:10:11
        String jia = "2020年11月11日 0:03:47";
        String pi = "2020年11月11日 0:10:11";

        SimpleDateFormat sdf = new SimpleDateFormat("yyyy年MM月dd日 HH:mm:ss");
        // 将String转化为Date后获取毫秒值
        long startTime = sdf.parse(start).getTime();
        long endTime = sdf.parse(end).getTime();
        long jiaTime = sdf.parse(jia).getTime();
        long piTime = sdf.parse(pi).getTime();

        // 通过毫秒值判断是否抢到
        if (jiaTime >= startTime && jiaTime <= endTime) {
            System.out.println("小贾抢到了");
        } else {
            System.out.println("小贾没抢到");
        }
        if (piTime >= startTime && piTime <= endTime) {
            System.out.println("小皮抢到了");
        } else {
            System.out.println("小皮没抢到");
        }
        
    }
}

四、JDK8时间日期类

4.1 JDK8新增日期类

  • LocalDate 表示日期(年月日)
  • LocalTime 表示时间(时分秒)
  • LocalDateTime 表示时间+ 日期 (年月日时分秒)

4.2 LocalDateTime创建方法

  • 方法说明

    方法名说明
    public static LocalDateTime now()获取当前系统时间
    public static LocalDateTime of (年, 月 , 日, 时, 分, 秒)使用指定年月日和时分秒初始化一个LocalDateTime对象
  • 示例代码

package com.xu.test;

import java.time.LocalDateTime;

public class Demo05 {
    public static void main(String[] args) {
        LocalDateTime now = LocalDateTime.now();
        System.out.println(now);
        
        LocalDateTime dateTime = LocalDateTime.of(2021, 8, 29, 0, 0, 0);
        System.out.println(dateTime);
    }

}

4.3LocalDateTime获取方法

  • 方法说明

    方法名说明
    public int getYear()获取年
    public int getMonthValue()获取月份(1-12)
    public int getDayOfMonth()获取月份中的第几天(1-31)
    public int getDayOfYear()获取一年中的第几天(1-366)
    public DayOfWeek getDayOfWeek()获取星期
    public int getMinute()获取分钟
    public int getHour()获取小时
  • 示例代码

package com.xu.test;

import com.sun.scenario.effect.impl.sw.sse.SSEBlend_SRC_OUTPeer;

import java.time.DayOfWeek;
import java.time.LocalDateTime;

public class Demo06 {
    /*
       public int getYear() 获取年
       public int getMonthValue() 获取月份(1-12)
       public int getDayOfMonth() 获取月份中的第几天(1-31)
       public int getDayOfYear()  获取一年中的第几天(1-366)
       public DayOfWeek getDayOfWeek()获取星期
       public int getMinute() 获取分钟
       public int getHour() 获取小时
   */
    public static void main(String[] args) {
        // public int getYear() 获取年
        LocalDateTime now = LocalDateTime.now();
        int year = now.getYear();
        System.out.println("现在的年份是:" + year);

        // public int getMonthValue() 获取月份(1-12)
        int monthValue = now.getMonthValue();
        System.out.println("现在的月份是:" + monthValue);

        // public int getDayOfMonth() 获取月份中的第几天(1-31)
        int dayOfMonth = now.getDayOfMonth();
        System.out.println("现在是几号:" + dayOfMonth);

        // public int getDayOfYear()  获取一年中的第几天(1-366)
        int dayOfYear = now.getDayOfYear();
        System.out.println("今天是一年的第几天:" + dayOfYear);

        // public DayOfWeek getDayOfWeek()获取星期
        DayOfWeek dayOfWeek = now.getDayOfWeek();
        System.out.println("今天是星期几(枚举类):" + dayOfWeek);

        // public int getMinute() 获取分钟
        int minute = now.getMinute();
        System.out.println("现在是多少分钟:" + minute);

        // public int getHour() 获取小时
        int hour = now.getHour();
        System.out.println("现在是多少时:" + hour);


    }
}

4.4 LocalDateTime转换方法

  • 方法说明

    方法名说明
    public LocalDate toLocalDate ()转换成为一个LocalDate对象
    public LocalTime toLocalTime ()转换成为一个LocalTime对象
  • 示例代码

package com.xu.test;

import java.time.LocalDate;
import java.time.LocalDateTime;
import java.time.LocalTime;

public class Demo07 {
    public static void main(String[] args) {
        LocalDateTime time = LocalDateTime.of(2021, 8, 29, 20, 18, 0);
        LocalDate localDate = time.toLocalDate();
        LocalTime localTime = time.toLocalTime();
        System.out.println(localDate);
        System.out.println(localTime);
    }
}

4.5 LocalDateTime格式化和解析

  • 方法说明

    方法名说明
    public String format (指定格式)把一个LocalDateTime格式化成为一个字符串
    public LocalDateTime parse (准备解析的字符串, 解析格式)把一个日期字符串解析成为一个LocalDateTime对象
    public static DateTimeFormatter ofPattern(String pattern)使用指定的日期模板获取一个日期格式化器DateTimeFormatter对象
  • 示例代码

package com.xu.test;

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

public class Demo08 {
    public static void main(String[] args) {
        method1();
        method2();


    }

    private static void method2() {
        String s = "2021-08-29 21:00:00";
        DateTimeFormatter pattern = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
        LocalDateTime parse = LocalDateTime.parse(s, pattern);
        System.out.println(parse);
    }

    private static void method1() {
        LocalDateTime now = LocalDateTime.now();
        //public String format (指定格式)   把一个LocalDateTime格式化成为一个字符串
        DateTimeFormatter pattern = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
        String s = now.format(pattern);
        System.out.println(s);
    }
}

4.6 LocalDateTime增加或者减少时间的方法

  • 方法说明

    方法名说明
    public LocalDateTime plusYears (long years)添加或者减去年
    public LocalDateTime plusMonths(long months)添加或者减去月
    public LocalDateTime plusDays(long days)添加或者减去日
    public LocalDateTime plusHours(long hours)添加或者减去时
    public LocalDateTime plusMinutes(long minutes)添加或者减去分
    public LocalDateTime plusSeconds(long seconds)添加或者减去秒
    public LocalDateTime plusWeeks(long weeks)添加或者减去周
  • 示例代码

package com.xu.test;


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

public class Demo09 {
    public static void main(String[] args) {
        LocalDateTime now = LocalDateTime.now();
        // public LocalDateTime plusYears (long years)添加或者减去年
        LocalDateTime newLocalDateTime = now.plusYears(1L);

        DateTimeFormatter pattern = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
        String nowTime = now.format(pattern);
        System.out.println(nowTime);  // 2021-08-29 22:06:46
        String format = newLocalDateTime.format(pattern);
        System.out.println(format);  // 2022-08-29 22:06:46

    }
}

4.7 LocalDateTime减少或者增加时间的方法

  • 方法说明

    方法名说明
    public LocalDateTime minusYears (long years)减去或者添加年
    public LocalDateTime minusMonths(long months)减去或者添加月
    public LocalDateTime minusDays(long days)减去或者添加日
    public LocalDateTime minusHours(long hours)减去或者添加时
    public LocalDateTime minusMinutes(long minutes)减去或者添加分
    public LocalDateTime minusSeconds(long seconds)减去或者添加秒
    public LocalDateTime minusWeeks(long weeks)减去或者添加周
  • 示例代码

package com.xu.test;


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

public class Demo10 {
    public static void main(String[] args) {
        LocalDateTime now = LocalDateTime.now();
        // public LocalDateTime  minusYears (long years)减去或者添加年
        LocalDateTime newLocalDateTime = now.minusYears(1L);

        DateTimeFormatter pattern = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
        String nowTime = now.format(pattern);
        System.out.println(nowTime);  // 2021-08-29 22:08:34
        String format = newLocalDateTime.format(pattern);
        System.out.println(format);  // 2020-08-29 22:08:34

    }
}

4.8 LocalDateTime修改方法

  • 方法说明

    方法名说明
    public LocalDateTime withYear(int year)直接修改年
    public LocalDateTime withMonth(int month)直接修改月
    public LocalDateTime withDayOfMonth(int dayofmonth)直接修改日期(一个月中的第几天)
    public LocalDateTime withDayOfYear(int dayOfYear)直接修改日期(一年中的第几天)
    public LocalDateTime withHour(int hour)直接修改小时
    public LocalDateTime withMinute(int minute)直接修改分钟
    public LocalDateTime withSecond(int second)直接修改秒
  • 示例代码

package com.xu.test;


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

public class Demo11 {
    public static void main(String[] args) {
        LocalDateTime now = LocalDateTime.now();
        DateTimeFormatter pattern = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
        String nowTime = now.format(pattern);
        System.out.println(nowTime);  // 2021-08-29 22:12:40
        // public LocalDateTime withYear(int year)直接修改年
        LocalDateTime withYear = now.withYear(2028);
        String newTime = withYear.format(pattern);
        System.out.println(newTime);  // 2028-08-29 22:12:40
        
    }
}

4.9 Period

  • 方法说明

    方法名说明
    public static Period between(开始时间,结束时间)计算两个“时间"的间隔
    public int getYears()获得这段时间的年数
    public int getMonths()获得此期间的总月数
    public int getDays()获得此期间的天数
    public long toTotalMonths()获取此期间的总月数
  • 示例代码

package com.xu.test;

import java.time.LocalDate;
import java.time.Period;

public class Demo12 {
    public static void main(String[] args) {
        LocalDate start = LocalDate.now();
        LocalDate end = LocalDate.of(2024, 7, 1);
        Period between = Period.between(start, end);
        int years = between.getYears();
        int days = between.getDays();
        int months = between.getMonths();
        long totalMonths = between.toTotalMonths();
        System.out.println("相隔的年数为"+years);
        System.out.println("相隔的月数为"+months);  
        System.out.println("相隔的天数为"+days);  // 不是总天数
        System.out.println("相隔的总月数为"+totalMonths);
    }
}

4.10 Duration

  • 方法说明

    方法名说明
    public static Durationbetween(开始时间,结束时间)计算两个“时间"的间隔
    public long toSeconds()获得此时间间隔的秒
    public int toMillis()获得此时间间隔的毫秒
    public int toNanos()获得此时间间隔的纳秒
  • 用法同上,不放代码了

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值