Java学习笔记(五)——时间相关类

news2024/9/21 16:47:20

文章目录

    • JDK7以前时间相关类
      • Date 时间类
        • 阅读源码
        • 练习
      • SimpleDateFormat 格式化时间
        • 作用
        • 构造方法
        • 常用方法
        • 日期和时间模式
        • 练习
      • Calendar 日历
        • 获取Calendar对象的方法
        • Calendar常用方法
    • JDK8新增时间相关类
      • 变化
      • Date类
        • ZoneId:时区
        • Instant:时间戳
        • ZoneDateTime:带时区的时间
      • 日期格式化类:SimpleDateFormat
        • DateTimeFormatter:用于时间的格式化和解析
      • 日历类:Calendar
        • LocalDate、LocalTime、LocalDateTime方法
        • LocalDate、LocalTime、LocalDateTime之间的转换
        • 判断生日
      • 工具类
        • Duration:时间间隔(秒、纳秒)
        • Period:时间间隔(年、月、日)
        • ChronoUnit:时间间隔(所有单位)

JDK7以前时间相关类

在这里插入图片描述

Date 时间类

阅读源码

在这里插入图片描述

在这里插入图片描述

在这里插入图片描述

在这里插入图片描述

import java.util.Date;

public class test13 {
    public static void main(String[] args) {

        //空参构造
        Date date1=new Date();
        System.out.println(date1);  //Sat Jan 06 16:08:25 CST 2024

        //有参构造
        Date date2=new Date(0L);
        System.out.println(date2);  //Thu Jan 01 08:00:00 CST 1970 —— 东八区在0的基础上加8个小时
        
        //修改时间,传递的参数为毫秒
        date2.setTime(1000L);
        System.out.println(date2);  //Thu Jan 01 08:00:01 CST 1970 —— 1000ms=1s

        //获取时间的毫秒值
        System.out.println(date2.getTime());  //1000
        
    }
}

练习

需求1:打印时间原点开始一年之后的时间

import java.util.Date;

public class test14 {
    public static void main(String[] args) {
        Date date=new Date(0L);
        long time=365*24*60*60*1000L;
        date.setTime(time);
        System.out.println(date);  //Fri Jan 01 08:00:00 CST 1971
    }
}
import java.util.Date;

public class test14 {
    public static void main(String[] args) {
        Date date=new Date(0L);
        long time=date.getTime();
        time+=365*24*60*60*1000L;
        date.setTime(time);
        System.out.println(date);  //Fri Jan 01 08:00:00 CST 1971
    }
}

需求2:定义任意两个Date对象,比较哪个时间在前,哪个时间在后

import java.util.Date;
import java.util.Random;

public class test15 {
    public static void main(String[] args) {
        Random random = new Random();
        Date date1 = new Date(Math.abs(random.nextInt()));
        Date date2 = new Date(Math.abs(random.nextInt()));
        long time1 = date1.getTime();
        long time2 = date2.getTime();
        if (time1 < time2) {
            System.out.println("date1时间在前");
        } else if (time1 > time2) {
            System.out.println("date2时间在前");
        } else {
            System.out.println("date1和date2时间相同");
        }
    }
}

SimpleDateFormat 格式化时间

作用
  • 格式化:把时间变成想要的格式
  • 解析:把字符串表示的时间变成Date对象
构造方法

在这里插入图片描述

常用方法

在这里插入图片描述

日期和时间模式

在这里插入图片描述

在这里插入图片描述

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

public class test16 {
    public static void main(String[] args) {
        SimpleDateFormat sdf1=new SimpleDateFormat();
        Date date=new Date(0L);
        String str1=sdf1.format(date);
        System.out.println(str1);  //70-1-1 上午8:00

        SimpleDateFormat sdf2=new SimpleDateFormat("yyyy年MM月dd日 HH:mm:ss");
        String str2=sdf2.format(date);
        System.out.println(str2);  //1970年01月01日 08:00:00

        SimpleDateFormat sdf3=new SimpleDateFormat("yyyy年MM月dd日 HH:mm:ss E");
        String str3=sdf3.format(date);
        System.out.println(str3);  //1970年01月01日 08:00:00 星期四
    }
}

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

public class test17 {
    public static void main(String[] args) throws ParseException {
        String str="2002-11-20 14:13:55";
        SimpleDateFormat sdf=new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        Date date = sdf.parse(str);
        System.out.println(date);  //Wed Nov 20 14:13:55 CST 2002
    }
}
练习

需求1:

假设,你的猪的出生年月日为:2000-09-26,请用字符串表示这个数据,并将其转换为:2000年09月26日

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

public class test18 {
    public static void main(String[] args) throws ParseException {
        //假设,你猪的出生年月日为:2000-09-26,请用字符串表示这个数据,并将其转换为:2000年09月26日
        String str = "2000-09-26";
        SimpleDateFormat sdf1 = new SimpleDateFormat("yyyy-MM-dd");
        Date date = sdf1.parse(str);

        SimpleDateFormat sdf2=new SimpleDateFormat("yyyy年MM月dd日");
        String result = sdf2.format(date);
        System.out.println(result);
    }
}

需求2:

在这里插入图片描述

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

public class test19 {
    public static void main(String[] args) throws ParseException {
        String time1 = "2023年11月11日 0:01:00";
        String time2 = "2023年11月11日 0:11:0";

        String start = "2023年11月11日 0:0:0";
        String end = "2023年11月11日 0:10:0";

        SimpleDateFormat sdf = new SimpleDateFormat("yyyy年MM月dd日 HH:mm:ss");
        
        Date time1_date = sdf.parse(time1);
        Date time2_date = sdf.parse(time2);
        Date start_date = sdf.parse(start);
        Date end_date = sdf.parse(end);

        long time1_time = time1_date.getTime();
        long time2_time = time2_date.getTime();
        long start_time = start_date.getTime();
        long end_time = end_date.getTime();

        if (time1_time >= start_time && time1_time <= end_time) {
            System.out.println("小贾下单成功!");
        } else {
            System.out.println("小贾下单失败!");
        }

        if (time2_time >= start_time && time2_time <= end_time) {
            System.out.println("小皮下单成功!");
        } else {
            System.out.println("小皮下单失败!");
        }
        
    }
}

Calendar 日历

在这里插入图片描述

Calendar代表系统当前时间的日历对象,可以单独修改、获取时间中的年、月、日。

注意:Calendar是一个抽象类,不能直接创建对象。

获取Calendar对象的方法

在这里插入图片描述

Calendar常用方法

在这里插入图片描述

import java.util.Calendar;
import java.util.Date;

public class test20 {
    public static void main(String[] args) {

        //底层原理:会根据系统的不同时区返回不同的日历对象
        //把相关的信息放在一个数组当中
        Calendar calendar=Calendar.getInstance();

        //月份:范围0~11,MONTH=0是1月
        //星期:1是星期天,DAY_OF_WEEK=1是星期天
        System.out.println(calendar);
        // java.util.GregorianCalendar[time=1704565565855,areFieldsSet=true,areAllFieldsSet=true,
        // lenient=true,zone=sun.util.calendar.ZoneInfo[id="Asia/Shanghai",offset=28800000,dstSavings=0,
        // useDaylight=false,transitions=31,lastRule=null],firstDayOfWeek=1,minimalDaysInFirstWeek=1,ERA=1,
        // YEAR=2024,MONTH=0,WEEK_OF_YEAR=2,WEEK_OF_MONTH=2,DAY_OF_MONTH=7,DAY_OF_YEAR=7,DAY_OF_WEEK=1,
        // DAY_OF_WEEK_IN_MONTH=1,AM_PM=0,HOUR=2,HOUR_OF_DAY=2,MINUTE=26,SECOND=5,MILLISECOND=855,
        // ZONE_OFFSET=28800000,DST_OFFSET=0]

        //修改日历代表时间
        Date date=new Date(0L);
        calendar.setTime(date);
        System.out.println(calendar);
        // java.util.GregorianCalendar[time=0,areFieldsSet=true,areAllFieldsSet=true,lenient=true,
        // zone=sun.util.calendar.ZoneInfo[id="Asia/Shanghai",offset=28800000,dstSavings=0,useDaylight=false,
        // transitions=31,lastRule=null],firstDayOfWeek=1,minimalDaysInFirstWeek=1,ERA=1,YEAR=1970,MONTH=0,
        // WEEK_OF_YEAR=1,WEEK_OF_MONTH=1,DAY_OF_MONTH=1,DAY_OF_YEAR=1,DAY_OF_WEEK=5,DAY_OF_WEEK_IN_MONTH=1,
        // AM_PM=0,HOUR=8,HOUR_OF_DAY=8,MINUTE=0,SECOND=0,MILLISECOND=0,ZONE_OFFSET=28800000,DST_OFFSET=0]

        //修改日历毫秒值
        calendar.setTimeInMillis(1000L);
        System.out.println(calendar);
        // java.util.GregorianCalendar[time=1000,areFieldsSet=true,areAllFieldsSet=true,lenient=true,
        // zone=sun.util.calendar.ZoneInfo[id="Asia/Shanghai",offset=28800000,dstSavings=0,useDaylight=false,
        // transitions=31,lastRule=null],firstDayOfWeek=1,minimalDaysInFirstWeek=1,ERA=1,YEAR=1970,MONTH=0,
        // WEEK_OF_YEAR=1,WEEK_OF_MONTH=1,DAY_OF_MONTH=1,DAY_OF_YEAR=1,DAY_OF_WEEK=5,DAY_OF_WEEK_IN_MONTH=1,
        // AM_PM=0,HOUR=8,HOUR_OF_DAY=8,MINUTE=0,SECOND=1,MILLISECOND=0,ZONE_OFFSET=28800000,DST_OFFSET=0]

        //获取日历信息
        System.out.println(calendar.get(Calendar.YEAR));  //1970
        System.out.println(calendar.get(Calendar.MONTH));  //0
        System.out.println(calendar.get(Calendar.DAY_OF_MONTH));  //1

        //修改日历中指定信息的值
        calendar.set(Calendar.YEAR,2024);
        System.out.println(calendar);
        //java.util.GregorianCalendar[time=?,areFieldsSet=false,areAllFieldsSet=true,lenient=true,
        // zone=sun.util.calendar.ZoneInfo[id="Asia/Shanghai",offset=28800000,dstSavings=0,useDaylight=false,
        // transitions=31,lastRule=null],firstDayOfWeek=1,minimalDaysInFirstWeek=1,ERA=1,YEAR=2024,MONTH=0,
        // WEEK_OF_YEAR=1,WEEK_OF_MONTH=1,DAY_OF_MONTH=1,DAY_OF_YEAR=1,DAY_OF_WEEK=5,DAY_OF_WEEK_IN_MONTH=1,
        // AM_PM=0,HOUR=8,HOUR_OF_DAY=8,MINUTE=0,SECOND=1,MILLISECOND=0,ZONE_OFFSET=28800000,DST_OFFSET=0]

        //某个字段增加指定值
        calendar.add(Calendar.YEAR,+5);
        System.out.println(calendar);
        // java.util.GregorianCalendar[time=?,areFieldsSet=false,areAllFieldsSet=true,lenient=true,
        // zone=sun.util.calendar.ZoneInfo[id="Asia/Shanghai",offset=28800000,dstSavings=0,useDaylight=false,
        // transitions=31,lastRule=null],firstDayOfWeek=1,minimalDaysInFirstWeek=1,ERA=1,YEAR=2029,MONTH=0,
        // WEEK_OF_YEAR=1,WEEK_OF_MONTH=1,DAY_OF_MONTH=1,DAY_OF_YEAR=1,DAY_OF_WEEK=2,DAY_OF_WEEK_IN_MONTH=1,
        // AM_PM=0,HOUR=8,HOUR_OF_DAY=8,MINUTE=0,SECOND=1,MILLISECOND=0,ZONE_OFFSET=28800000,DST_OFFSET=0]

        //某个字段减少指定值
        calendar.add(Calendar.YEAR,-10);
        System.out.println(calendar);
        // java.util.GregorianCalendar[time=?,areFieldsSet=false,areAllFieldsSet=true,lenient=true,
        // zone=sun.util.calendar.ZoneInfo[id="Asia/Shanghai",offset=28800000,dstSavings=0,useDaylight=false,
        // transitions=31,lastRule=null],firstDayOfWeek=1,minimalDaysInFirstWeek=1,ERA=1,YEAR=2019,MONTH=0,
        // WEEK_OF_YEAR=1,WEEK_OF_MONTH=1,DAY_OF_MONTH=1,DAY_OF_YEAR=1,DAY_OF_WEEK=2,DAY_OF_WEEK_IN_MONTH=1,
        // AM_PM=0,HOUR=8,HOUR_OF_DAY=8,MINUTE=0,SECOND=1,MILLISECOND=0,ZONE_OFFSET=28800000,DST_OFFSET=0]
    }
}

JDK8新增时间相关类

在这里插入图片描述

变化

在这里插入图片描述

Date类

ZoneId:时区

在这里插入图片描述

在这里插入图片描述

import java.time.ZoneId;
import java.util.Set;

public class test21 {
    public static void main(String[] args) {
        // 获取所有时区名称
        Set<String> availableZoneIds = ZoneId.getAvailableZoneIds();
        System.out.println(availableZoneIds);
        System.out.println(availableZoneIds.size());  //603

        // 获取当前系统时区
        ZoneId systemDefault = ZoneId.systemDefault();
        System.out.println(systemDefault);  //Asia/Shanghai

        // 获取指定时区
        ZoneId zoneId = ZoneId.of("America/Marigot");
        System.out.println(zoneId);  //America/Marigot
    }
}
Instant:时间戳

在这里插入图片描述

import java.time.Instant;
import java.time.ZoneId;
import java.time.ZonedDateTime;

public class test22 {
    public static void main(String[] args) {
        // 获取世界标准时间
        Instant now = Instant.now();
        System.out.println(now);  //2024-01-06T19:24:29.595Z

        // 获取当前东八区时间
        ZoneId zoneId = ZoneId.of("Asia/Shanghai");
        ZonedDateTime now_eight=now.atZone(zoneId);
        System.out.println(now_eight);  //2024-01-07T03:24:29.595+08:00[Asia/Shanghai]

        // 根据毫秒获取Instant对象
        Instant ofEpochMilli = Instant.ofEpochMilli(1000L);
        System.out.println(ofEpochMilli);  //970-01-01T00:00:01Z

        // 根据秒获取Instant对象
        Instant ofEpochSecond = Instant.ofEpochSecond(40);
        System.out.println(ofEpochSecond);  //1970-01-01T00:00:40Z

        // 根据秒+纳秒获取Instant对象
        Instant ofEpochSecond1 = Instant.ofEpochSecond(20, 20);  //1970-01-01T00:00:20.000000020Z
        System.out.println(ofEpochSecond1);

        // 判断前后
        Instant instant1=Instant.ofEpochMilli(1000L);
        Instant instant2=Instant.ofEpochMilli(2000L);

        boolean result1=instant1.isAfter(instant2);  //false
        boolean result2=instant1.isBefore(instant2);  //true

        System.out.println(result1);
        System.out.println(result2);

        // 减少/增加
        Instant instant3=Instant.ofEpochMilli(3000L);
        Instant instant4=Instant.ofEpochMilli(4000L);

        Instant instant5=instant3.minusMillis(1000L);
        Instant instant6=instant4.plusMillis(1000L);

        System.out.println(instant3);  //1970-01-01T00:00:03Z
        System.out.println(instant4);  //1970-01-01T00:00:04Z
        System.out.println(instant5);  //1970-01-01T00:00:02Z
        System.out.println(instant6);  //1970-01-01T00:00:05Z
    }
}
ZoneDateTime:带时区的时间

在这里插入图片描述

import java.time.Instant;
import java.time.ZoneId;
import java.time.ZonedDateTime;

public class test23 {
    public static void main(String[] args) {
        // 获取当前带时区的时间
        ZonedDateTime zdt=ZonedDateTime.now();
        System.out.println(zdt);  //2024-01-07T13:54:13.668+08:00[Asia/Shanghai]

        // 获取指定时间
        ZonedDateTime zonedDateTime=ZonedDateTime.of(2024,1,7,13,50,33,20, ZoneId.of("Asia/Shanghai"));
        System.out.println(zonedDateTime);  //2024-01-07T13:50:33.000000020+08:00[Asia/Shanghai]

        // 通过Instant+时区获取指定时间
        Instant instant=Instant.ofEpochMilli(1000L);
        ZoneId zoneId=ZoneId.of("Asia/Shanghai");
        ZonedDateTime zonedDateTime10 = instant.atZone(zoneId);
        System.out.println(zonedDateTime10);  //1970-01-01T08:00:01+08:00[Asia/Shanghai]

        // 修改时间
        ZonedDateTime zonedDateTime1 = zonedDateTime.withYear(2019);
        ZonedDateTime zonedDateTime2 = zonedDateTime.withMonth(9);
        ZonedDateTime zonedDateTime3 = zonedDateTime.withDayOfMonth(26);

        System.out.println(zonedDateTime);  //2024-01-07T13:50:33.000000020+08:00[Asia/Shanghai]

        System.out.println(zonedDateTime1);  //2019-01-07T13:50:33.000000020+08:00[Asia/Shanghai]
        System.out.println(zonedDateTime2);  //2024-09-07T13:50:33.000000020+08:00[Asia/Shanghai]
        System.out.println(zonedDateTime3);  //2024-01-26T13:50:33.000000020+08:00[Asia/Shanghai]

        // 减少时间
        ZonedDateTime zonedDateTime4 = zonedDateTime.minusYears(4);
        ZonedDateTime zonedDateTime5 = zonedDateTime.minusMonths(2);
        ZonedDateTime zonedDateTime6 = zonedDateTime.minusDays(4);
        
        System.out.println(zonedDateTime4);  //2020-01-07T13:50:33.000000020+08:00[Asia/Shanghai]
        System.out.println(zonedDateTime5);  //2023-11-07T13:50:33.000000020+08:00[Asia/Shanghai]
        System.out.println(zonedDateTime6);  //2024-01-03T13:50:33.000000020+08:00[Asia/Shanghai]

        // 增加时间
        ZonedDateTime zonedDateTime7 = zonedDateTime.plusYears(10);
        ZonedDateTime zonedDateTime8 = zonedDateTime.plusMonths(4);
        ZonedDateTime zonedDateTime9 = zonedDateTime.plusDays(10);

        System.out.println(zonedDateTime7);  //2034-01-07T13:50:33.000000020+08:00[Asia/Shanghai]
        System.out.println(zonedDateTime8);  //2024-05-07T13:50:33.000000020+08:00[Asia/Shanghai]
        System.out.println(zonedDateTime9);  //2024-01-17T13:50:33.000000020+08:00[Asia/Shanghai]
    }
}

日期格式化类:SimpleDateFormat

DateTimeFormatter:用于时间的格式化和解析

在这里插入图片描述

import java.time.Instant;
import java.time.ZoneId;
import java.time.ZonedDateTime;
import java.time.format.DateTimeFormatter;

public class test24 {
    public static void main(String[] args) {
        // 获取格式对象
        DateTimeFormatter stf=DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");

        // 获取时间对象
        ZonedDateTime zonedDateTime = Instant.now().atZone(ZoneId.of("Asia/Shanghai"));

        // 格式化时间对象
        String format = stf.format(zonedDateTime);
        
        System.out.println(format);  //2024-01-07 14:19:12
    }
}

日历类:Calendar

LocalDate、LocalTime、LocalDateTime方法

在这里插入图片描述

LocalDate、LocalTime、LocalDateTime之间的转换

在这里插入图片描述

import java.time.*;

public class test25 {
    public static void main(String[] args) {

        // LocalDate
        // 获取当前时间
        LocalDate localDate=LocalDate.now();
        System.out.println(localDate);  //2024-01-07

        LocalDateTime localDateTime1 = localDate.atStartOfDay();
        System.out.println(localDateTime1);  //2024-01-07T00:00

        // 获取日历中指定信息
        int year = localDate.getYear();
        Month month = localDate.getMonth();
        int month1=month.getValue();
        int dayOfMonth = localDate.getDayOfMonth();

        System.out.println(year);  //2024
        System.out.println(month);  //JANUARY
        System.out.println(month1);  //1
        System.out.println(dayOfMonth);  //7

        // 比较时间前后
        LocalDate localDate1=LocalDate.of(2022,11,20);
        boolean after = localDate.isAfter(localDate1);
        boolean before = localDate.isBefore(localDate1);

        System.out.println(after);  //true
        System.out.println(before);  //false

        // 修改日历信息
        LocalDate localDate2 = localDate1.withYear(2023);
        LocalDate localDate3 = localDate1.withMonth(12);
        LocalDate localDate4 = localDate1.withDayOfMonth(29);

        System.out.println(localDate2);  //2023-11-20
        System.out.println(localDate3);  //2022-12-20
        System.out.println(localDate4);  //2022-11-29

        // LocalTime
        LocalTime localTime=LocalTime.now();  //14:29:51.394
        LocalTime localTime1 = LocalTime.now(ZoneId.of("America/Cuiaba"));  //02:29:51.394

        System.out.println(localTime);
        System.out.println(localTime1);

        // LocalDateTime
        LocalDateTime localDateTime=LocalDateTime.now();
        LocalDateTime localDateTime5=LocalDateTime.now(ZoneId.of("America/Cuiaba"));

        System.out.println(localDateTime);  //2024-01-07T14:31:12.884
        System.out.println(localDateTime5);  //2024-01-07T02:31:12.884

        // 转换
        LocalDate localDate5 = localDateTime.toLocalDate();
        LocalTime localTime2 = localDateTime.toLocalTime();

        System.out.println(localDate5);  //2024-01-07
        System.out.println(localTime2);  //14:44:20.837
    }
}
判断生日
import java.time.LocalDate;
import java.time.MonthDay;

public class test26 {
    public static void main(String[] args) {
        LocalDate birth=LocalDate.of(2002,11,20);
        LocalDate now=LocalDate.now();

        MonthDay birthMonthDay=MonthDay.of(birth.getMonthValue(),birth.getDayOfMonth());
        MonthDay nowMonthDay=MonthDay.of(now.getMonthValue(),now.getDayOfMonth());
        
        if(birthMonthDay.equals(nowMonthDay)){
            System.out.println("今天生日!");
        }
    }
}

工具类

Duration:时间间隔(秒、纳秒)
import java.time.Duration;
import java.time.LocalTime;

public class test28 {
    public static void main(String[] args) {
        // Duration
        LocalTime now=LocalTime.now();
        LocalTime localTime=LocalTime.of(12,0,0);

        Duration duration=Duration.between(localTime,now);
        System.out.println(duration);  //PT3H4M39.451S
        System.out.println(duration.toDays());  //0
        System.out.println(duration.toHours());  //3
        System.out.println(duration.toMinutes());  //184
        System.out.println(duration.toMillis());  //11079451
        System.out.println(duration.toNanos());  //11079451000000
    }
}
Period:时间间隔(年、月、日)
import java.time.Duration;
import java.time.LocalDate;
import java.time.LocalTime;
import java.time.Period;

public class test27 {
    public static void main(String[] args) {
        // Period
        LocalDate now=LocalDate.now();
        LocalDate birth=LocalDate.of(2002,11,20);
        Period period=Period.between(birth,now);  //第二个参数减去第一个参数

        System.out.println(period);  //P21Y1M18D
        System.out.println(period.getYears());  //21
        System.out.println(period.getMonths());  //1
        System.out.println(period.getDays());  //18
        System.out.println(period.toTotalMonths());  //253

    }
}
ChronoUnit:时间间隔(所有单位)
import java.time.LocalDate;
import java.time.LocalDateTime;
import java.time.temporal.ChronoUnit;

public class test29 {
    public static void main(String[] args) {
        LocalDateTime now=LocalDateTime.now();
        LocalDateTime localDateTime=LocalDateTime.of(2022,11,20,12,54,30);

        System.out.println(ChronoUnit.YEARS.between(localDateTime,now));  //1
        System.out.println(ChronoUnit.MONTHS.between(localDateTime,now));  //13
        System.out.println(ChronoUnit.DAYS.between(localDateTime,now));  //413
        System.out.println(ChronoUnit.HOURS.between(localDateTime,now));  //9914
        System.out.println(ChronoUnit.MINUTES.between(localDateTime,now));  //594855
        System.out.println(ChronoUnit.SECONDS.between(localDateTime,now));  //35691339
    }
}

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.coloradmin.cn/o/1365907.html

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈,一经查实,立即删除!

相关文章

ECharts 实现省份在对应地图的中心位置

使用 ECharts 下载的中国省市区的json文件不是居中的(如下图所示)&#xff0c;此时需要修改json文件中的 cp 地理位置&#xff0c;设置成每个省份的中心位置 {"type": "FeatureCollection","features":[{ "type": "Feature"…

C++ 手写堆 || 堆模版题:堆排序

输入一个长度为 n 的整数数列&#xff0c;从小到大输出前 m 小的数。 输入格式 第一行包含整数 n 和 m 。 第二行包含 n 个整数&#xff0c;表示整数数列。 输出格式 共一行&#xff0c;包含 m 个整数&#xff0c;表示整数数列中前 m 小的数。 数据范围 1≤m≤n≤105 &…

护眼灯色温多少合适?盘点合适色温的护眼台灯

有了孩子&#xff0c;就等于同时有了软肋和铠甲&#xff0c;也总是在自己的能力范围内&#xff0c;把最好的东西给他。当孩子开始学习知识后更是如此&#xff0c;能力范围内最好的教育资源、最好的学习环境&#xff0c;以及各种与之配套的学习用具。护眼台灯在这时候就安排上了…

热钱涌向线控底盘!XYZ全栈集成引领新风向

在车身、底盘部分&#xff0c;中央计算区域控制带动传统车控、底盘及动力控制ECU市场迎来新一轮技术升级和域融合窗口期。线控制动、转向及空气悬架&#xff0c;正在加速与智能驾驶融合并进一步提升驾乘体验。 12月13-15日&#xff0c;2023&#xff08;第七届&#xff09;高工…

插画新手必看!13个免费UI插画素材网站,轻松打造炫酷设计!

即时设计 作为一个专业的设计网站&#xff0c;即时设计在很多情况下也可以作为一个高质量的插图网站使用。它可以为用户提供近5万个设计材料和模板&#xff0c;其中插图占据了很大的空间&#xff0c;可以为用户的设计提供很多帮助。在搜索插图材料的同时&#xff0c;还可以获取…

强化学习7——价值迭代算法在强化学习中的应用

价值迭代算法 价值迭代算法相对于策略迭代更加直接&#xff0c;它直接根据以下公式来迭代更新。 V ∗ ( s ) max ⁡ a ∈ A { r ( s , a ) γ ∑ s ′ ∈ S P ( s ′ ∣ s , a ) V ∗ ( s ′ ) } V^*(s)\max_{a\in\mathcal{A}}\{r(s,a)\gamma\sum_{s\in\mathcal{S}}P(s|s,…

二叉树的深度和高度问题(算法村第八关白银挑战)

二叉树的最大深度 104. 二叉树的最大深度 - 力扣&#xff08;LeetCode&#xff09; 给定一个二叉树 root &#xff0c;返回其最大深度。 二叉树的 最大深度 是指从根节点到最远叶子节点的最长路径上的节点数。 示例 1&#xff1a; 输入&#xff1a;root [3,9,20,null,null…

爱奇艺的cmd5x签名校验算法及视频下载

点击上方↑↑↑蓝字[协议分析与还原]关注我们 “ js分析&#xff0c;分析爱奇艺的cmd5x校验值。” 最近来了个从web网页自动下载爱奇艺的视频内容的需求&#xff0c;本以为很简单&#xff0c;却发现里面还是有些门道的&#xff0c;需要解决里面的校验的问题&#xff0c;特记录。…

Unity C# 枚举多选

枚举多选 &#x1f96a;例子&#x1f354;判断 &#x1f96a;例子 [System.Flags]public enum TestEnum{ None 0,Rooms 1 << 1,Walls1<<2,Objects1<<3,Slabs 1 << 4,All Rooms|Walls|Objects|Slabs}&#x1f354;判断 TestEnum test TestEnum.R…

(一)看参考手册学stm32基于hal库,点灯时钟配置

&#xff08;一&#xff09;看参考手册学stm32基于hal库&#xff0c;点灯时钟配置 这篇文章主要是个人的学习经验&#xff0c;想分享出来供大家提供思路&#xff0c;如果其中有不足之处请批评指正哈。 废话不多说直接开始主题&#xff0c;本人是基于STM32F407VET6芯片&#xf…

解析电商直播发展现状:成都天府锋巢直播基地能做什么?

近日&#xff0c;电商巨浪席卷过后&#xff0c;千舟如何“再”过万重山&#xff0c;已成为无数电商从业者的一轮新课题。成都新兴直播基地——天府锋巢直播产业基地&#xff0c;正在致力于打造一个包含电商直播、娱乐直播、跨境直播等多种直播业态的全域直播基地。新一轮直播业…

80/20法则-扫盲和复习篇

80/20法则-扫盲和复习篇 一、80/20法则二、对于目标三、时间管理应用四、“二八定律”基本内容总结 一、80/20法则 “80/20法则”是20世纪初意大利统计学家、经济学家维尔弗雷多帕累托提出的&#xff0c;他指出&#xff1a;在任何特定群体中&#xff0c;重要的因子通常只占少数…

基于spark的个性化招聘推荐系统

介绍 本就业推荐系统是一个基于Spark框架的个性化推荐平台&#xff0c;使用Python Django框架、Vue和Element-Plus UI组件库构建而成。该系统通过Scrapy爬虫框架抓取招聘网站的职位数据&#xff0c;用户可以根据关键词查询符合条件的职位信息&#xff0c;同时还提供了基于协同…

线性渐变linear-gradient——线性渐变实现虚线斜线条纹

1.效果图 2.html <div class"box"><div class"address-edit"></div></div> 3.css <style>*{margin: 0;padding: 0;}.box{position: relative;width: 100vw;height: 300px;background-color: #fff;}.address-edit::before…

结构体(structure)的认识

前言——————希望现在在努力的各位都能感动以后享受成功的自己&#xff01; 今天我们来了解了解一下结构体&#xff0c;结构体又有什么奥妙呢&#xff0c;废话不多说&#xff0c;何为结构体呢&#xff1f;------->结构是⼀些值的集合&#xff0c;这些值称为成员变量。结…

leetcode:滑动窗口

目录 1.定长滑动窗口 1.1 几乎唯一子数组的最大和(使用map来计数) 1.2 长度为k子数组中的最大和 2.不定长滑动窗口 2.1 最多k个重复元素的最长子数组 2.2 绝对差不超过限制的最长连续子数组(multiset&#xff09; 2.3 将x减到0的最小操作数(正难则反 逆向思维) 2.4 统计…

分布式架构那些事儿

今天给大家搬运一波福利&#xff0c;那就是分布式架构那些事&#xff01;说到分布式架构&#xff0c;你是不是觉得高大上、遥不可及&#xff1f;别慌&#xff0c;我会讲得通俗易懂&#xff0c;让你秒变架构大神&#xff01;听完之后直接带回家装逼&#xff01;一起来Get新知识&…

< Linux >缓冲区

在上一篇文件的重定向&#xff0c;通常会涉及文件描述符的操控。文件描述符1&#xff08;fd 1&#xff09;通常代表着标准输出&#xff08;stdout&#xff09;&#xff0c;它默认是指向用户的终端或控制台。当执行文件重定向操作时&#xff0c;如果我们关闭文件描述符1&#xf…

SurfaceFlinger的commit/handleTransaction分析

整体背景介绍 hi&#xff0c;粉丝朋友们&#xff1a; 大家好&#xff01;本节我们来讲解一下SurfaceFlinger主要合成工作的第一个阶段任务commit 一般SurfaceFlinger端的合成工作主要有两个 1.commit 主要就是处理app端发起的一系列transaction的事务请求&#xff0c;需要对这…

Python笔记03-判断和循环

文章目录 比较运算符if-else语句while语句for循环循环中断 比较运算符 字面量True表示真&#xff0c;字面量False表示假 if-else语句 if语句判断条件的结果一定要是布尔类型 不要忘记判断条件后的&#xff1a; 归属于if语句的代码块&#xff0c;需在前方填充4个空格缩进 age…