LocalDateTime 字符串与时间戳的相互转换

主要介绍LocalDateTime的格式化字符串与时间戳的相互转换

常见带日期时间格式:

字段名字段值
api格式DateTimeFormatter.ISO_LOCAL_DATE_TIME
字符串patternyyyy-MM-dd’T’HH:mm:ss.SSS’
示例2022-06-15T22:06:29.483
字符串patternyyyy-MM-dd HH:mm:ss
示例2022-06-15 22:06:29

1. 使用默认格式和默认时区

package com.ysx.utils.datetime;

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

/**
 * LocalDateTime 字符串与时间戳的相互转换
 *
 * @author youngbear
 * @email youngbear@aliyun.com
 * @date 2024-07-07 11:38
 * @blog <a href="https://blog.csdn.net/next_second">...</a>
 * @github <a href="https://github.com/YoungBear">...</a>
 * @description
 */
public class LocalDateTimeFormatterUtils {

    /**
     * 默认时间日期格式字符串
     * yyyy-MM-dd HH:mm:ss
     * eg.
     * 2022-06-15 22:06:29
     */
    private static final DateTimeFormatter DEFAULT_FORMATTER = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");

    /**
     * 根据时间戳格式化为字符串
     * 指定格式的时间日期格式
     * 使用系统默认时区
     *
     * @param timestamp 时间戳 毫秒 如 1655301989483L
     * @return 格式化后的字符串 如 2022-06-15T22:06:29.483
     */
    public static String long2String(long timestamp) {
        return Instant.ofEpochMilli(timestamp).atZone(ZoneId.systemDefault()).toLocalDateTime().format(DEFAULT_FORMATTER);
    }

    /**
     * 根据字符串解析时间戳
     * 默认格式的时间日期格式
     * 默认时区
     *
     * @param dateString 格式化后的字符串 如 2022-06-15T17:06:29.483
     * @return 时间戳 毫秒 如 1655301989483L
     */
    public static long string2long(String dateString) {
        return LocalDateTime.parse(dateString, DEFAULT_FORMATTER).atZone(ZoneId.systemDefault()).toInstant().toEpochMilli();
    }

}

对应单元测试

package com.ysx.utils.datetime;

import org.junit.jupiter.api.DisplayName;
import org.junit.jupiter.api.Test;
import org.mockito.MockedStatic;
import org.mockito.Mockito;

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

import static org.junit.jupiter.api.Assertions.assertEquals;

/**
 * @author youngbear
 * @email youngbear@aliyun.com
 * @date 2024-07-07 11:55
 * @blog <a href="https://blog.csdn.net/next_second">...</a>
 * @github <a href="https://github.com/YoungBear">...</a>
 * @description unit test for {@link LocalDateTimeFormatterUtils}
 */
public class LocalDateTimeFormatterUtilsTest {

    @Test
    @DisplayName("根据时间戳格式化为字符串 默认格式 默认时区")
    public void long2StringTest1() {
        long timestamp = 1655301989483L;
        ZoneId zoneIdShanghai = ZoneId.of("Asia/Shanghai");
        try (MockedStatic<ZoneId> mockedZonedId = Mockito.mockStatic(ZoneId.class)) {
            mockedZonedId.when(ZoneId::systemDefault).thenReturn(zoneIdShanghai);
            assertEquals("2022-06-15 22:06:29", LocalDateTimeFormatterUtils.long2String(timestamp));
        }
    }

    @Test
    @DisplayName("根据字符串解析为时间戳 默认格式 默认时区")
    public void string2longTest1() {
        ZoneId zoneIdShanghai = ZoneId.of("Asia/Shanghai");
        try (MockedStatic<ZoneId> mockedZonedId = Mockito.mockStatic(ZoneId.class)) {
            mockedZonedId.when(ZoneId::systemDefault).thenReturn(zoneIdShanghai);
            assertEquals(1655301989000L, LocalDateTimeFormatterUtils.string2long("2022-06-15 22:06:29"));
        }
    }

}

2. 更多方法(指定格式和指定时区)

package com.ysx.utils.datetime;

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

/**
 * LocalDateTime 字符串与时间戳的相互转换
 *
 * @author youngbear
 * @email youngbear@aliyun.com
 * @date 2024-07-07 11:38
 * @blog <a href="https://blog.csdn.net/next_second">...</a>
 * @github <a href="https://github.com/YoungBear">...</a>
 * @description
 */
public class LocalDateTimeFormatterUtils {

    /**
     * 默认时间日期格式字符串
     * yyyy-MM-dd HH:mm:ss
     * eg.
     * 2022-06-15 22:06:29
     */
    private static final DateTimeFormatter DEFAULT_FORMATTER = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");

    /**
     * 根据时间戳格式化为字符串
     * 指定格式的时间日期格式
     * 使用系统默认时区
     *
     * @param timestamp 时间戳 毫秒 如 1655301989483L
     * @return 格式化后的字符串 如 2022-06-15T22:06:29.483
     */
    public static String long2String(long timestamp) {
        return Instant.ofEpochMilli(timestamp).atZone(ZoneId.systemDefault()).toLocalDateTime().format(DEFAULT_FORMATTER);
    }

    /**
     * 根据时间戳格式化为字符串
     * 指定格式的时间日期格式
     * 使用系统默认时区
     *
     * @param timestamp 时间戳 毫秒 如 1655301989483L
     * @param formatter formatter 如 DateTimeFormatter.ISO_LOCAL_DATE_TIME
     * @return 格式化后的字符串 如 2022-06-15T17:06:29.483
     */
    public static String long2String(long timestamp, DateTimeFormatter formatter) {
        return Instant.ofEpochMilli(timestamp).atZone(ZoneId.systemDefault()).toLocalDateTime().format(formatter);
    }

    /**
     * 根据时间戳格式化为字符串
     * 默认格式的时间日期格式
     * 指定时区
     *
     * @param timestamp 时间戳 毫秒 如 1655301989483L
     * @param zoneId 时区信息 如 ZoneId.of("Europe/Moscow")
     * @return 格式化后的字符串 如 2022-06-15T17:06:29.483
     */
    public static String long2String(long timestamp, ZoneId zoneId) {
        return Instant.ofEpochMilli(timestamp).atZone(zoneId).toLocalDateTime().format(DEFAULT_FORMATTER);
    }


    /**
     * 根据时间戳格式化为字符串
     * 指定格式的时间日期格式
     * 指定时区
     *
     * @param timestamp 时间戳 毫秒 如 1655301989483L
     * @param formatter formatter 如 DateTimeFormatter.ISO_LOCAL_DATE_TIME
     * @param zoneId 时区信息 如 ZoneId.of("Europe/Moscow")
     * @return 格式化后的字符串 如 2022-06-15T17:06:29.483
     */
    public static String long2String(long timestamp, DateTimeFormatter formatter, ZoneId zoneId) {
        return Instant.ofEpochMilli(timestamp).atZone(zoneId).toLocalDateTime().format(formatter);
    }

    /**
     * 根据字符串解析时间戳
     * 默认格式的时间日期格式
     * 默认时区
     *
     * @param dateString 格式化后的字符串 如 2022-06-15T17:06:29.483
     * @return 时间戳 毫秒 如 1655301989483L
     */
    public static long string2long(String dateString) {
        return LocalDateTime.parse(dateString, DEFAULT_FORMATTER).atZone(ZoneId.systemDefault()).toInstant().toEpochMilli();
    }

    /**
     * 根据字符串解析时间戳
     * 指定格式的时间日期格式
     * 默认时区
     *
     * @param dateString 格式化后的字符串 如 2022-06-15T17:06:29.483
     * @param formatter formatter 如 DateTimeFormatter.ISO_LOCAL_DATE_TIME
     * @return 时间戳 毫秒 如 1655301989483L
     */
    public static long string2long(String dateString, DateTimeFormatter formatter) {
        return LocalDateTime.parse(dateString, formatter).atZone(ZoneId.systemDefault()).toInstant().toEpochMilli();
    }

    /**
     * 根据字符串解析时间戳
     * 默认格式的时间日期格式
     * 指定时区
     *
     * @param dateString 格式化后的字符串 如 2022-06-15T17:06:29.483
     * @param zoneId 时区信息 如 ZoneId.of("Europe/Moscow")
     * @return 时间戳 毫秒 如 1655301989483L
     */
    public static long string2long(String dateString, ZoneId zoneId) {
        return LocalDateTime.parse(dateString, DEFAULT_FORMATTER).atZone(zoneId).toInstant().toEpochMilli();
    }

    /**
     * 根据字符串解析时间戳
     * 指定格式的时间日期格式
     * 指定时区
     *
     * @param dateString 格式化后的字符串 如 2022-06-15T17:06:29.483
     * @param formatter formatter 如 DateTimeFormatter.ISO_LOCAL_DATE_TIME
     * @param zoneId 时区信息 如 ZoneId.of("Europe/Moscow")
     * @return 时间戳 毫秒 如 1655301989483L
     */
    public static long string2long(String dateString, DateTimeFormatter formatter, ZoneId zoneId) {
        return LocalDateTime.parse(dateString, formatter).atZone(zoneId).toInstant().toEpochMilli();
    }

}

对应单元测试

package com.ysx.utils.datetime;

import org.junit.jupiter.api.DisplayName;
import org.junit.jupiter.api.Test;
import org.mockito.MockedStatic;
import org.mockito.Mockito;

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

import static org.junit.jupiter.api.Assertions.assertEquals;

/**
 * @author youngbear
 * @email youngbear@aliyun.com
 * @date 2024-07-07 11:55
 * @blog <a href="https://blog.csdn.net/next_second">...</a>
 * @github <a href="https://github.com/YoungBear">...</a>
 * @description unit test for {@link LocalDateTimeFormatterUtils}
 */
public class LocalDateTimeFormatterUtilsTest {

    @Test
    @DisplayName("根据时间戳格式化为字符串 默认格式 默认时区")
    public void long2StringTest1() {
        long timestamp = 1655301989483L;
        ZoneId zoneIdShanghai = ZoneId.of("Asia/Shanghai");
        try (MockedStatic<ZoneId> mockedZonedId = Mockito.mockStatic(ZoneId.class)) {
            mockedZonedId.when(ZoneId::systemDefault).thenReturn(zoneIdShanghai);
            assertEquals("2022-06-15 22:06:29", LocalDateTimeFormatterUtils.long2String(timestamp));
        }
    }

    @Test
    @DisplayName("根据时间戳格式化为字符串 指定格式 默认时区")
    public void long2StringTest2() {
        long timestamp = 1655301989483L;
        DateTimeFormatter formatter1 = DateTimeFormatter.ISO_LOCAL_DATE_TIME;
        DateTimeFormatter formatter2 = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
        ZoneId zoneIdShanghai = ZoneId.of("Asia/Shanghai");
        try (MockedStatic<ZoneId> mockedZonedId = Mockito.mockStatic(ZoneId.class)) {
            mockedZonedId.when(ZoneId::systemDefault).thenReturn(zoneIdShanghai);
            assertEquals("2022-06-15T22:06:29.483", LocalDateTimeFormatterUtils.long2String(timestamp, formatter1));
            assertEquals("2022-06-15 22:06:29", LocalDateTimeFormatterUtils.long2String(timestamp, formatter2));
        }
    }

    @Test
    @DisplayName("根据时间戳格式化为字符串 默认格式 指定时区")
    public void long2StringTest3() {
        long timestamp = 1655301989483L;

        ZoneId zoneIdShanghai = ZoneId.of("Asia/Shanghai");
        ZoneId zoneIdMoscow = ZoneId.of("Europe/Moscow");
        ZoneId zoneIdParis = ZoneId.of("Europe/Paris");
        ZoneId zoneIdLos_Angeles = ZoneId.of("America/Los_Angeles");

        assertEquals("2022-06-15 22:06:29", LocalDateTimeFormatterUtils.long2String(timestamp, zoneIdShanghai));
        assertEquals("2022-06-15 17:06:29", LocalDateTimeFormatterUtils.long2String(timestamp, zoneIdMoscow));
        assertEquals("2022-06-15 16:06:29", LocalDateTimeFormatterUtils.long2String(timestamp, zoneIdParis));
        assertEquals("2022-06-15 07:06:29", LocalDateTimeFormatterUtils.long2String(timestamp, zoneIdLos_Angeles));
    }

    @Test
    @DisplayName("根据时间戳格式化为字符串 指定格式 指定时区")
    public void long2StringTest4() {
        long timestamp = 1655301989483L;
        DateTimeFormatter formatter1 = DateTimeFormatter.ISO_LOCAL_DATE_TIME;
        DateTimeFormatter formatter2 = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");

        ZoneId zoneIdShanghai = ZoneId.of("Asia/Shanghai");
        ZoneId zoneIdMoscow = ZoneId.of("Europe/Moscow");
        ZoneId zoneIdParis = ZoneId.of("Europe/Paris");
        ZoneId zoneIdLos_Angeles = ZoneId.of("America/Los_Angeles");

        assertEquals("2022-06-15T22:06:29.483", LocalDateTimeFormatterUtils.long2String(timestamp, formatter1, zoneIdShanghai));
        assertEquals("2022-06-15T17:06:29.483", LocalDateTimeFormatterUtils.long2String(timestamp, formatter1, zoneIdMoscow));
        assertEquals("2022-06-15T16:06:29.483", LocalDateTimeFormatterUtils.long2String(timestamp, formatter1, zoneIdParis));
        assertEquals("2022-06-15T07:06:29.483", LocalDateTimeFormatterUtils.long2String(timestamp, formatter1, zoneIdLos_Angeles));

        assertEquals("2022-06-15 22:06:29", LocalDateTimeFormatterUtils.long2String(timestamp, formatter2, zoneIdShanghai));
        assertEquals("2022-06-15 17:06:29", LocalDateTimeFormatterUtils.long2String(timestamp, formatter2, zoneIdMoscow));
        assertEquals("2022-06-15 16:06:29", LocalDateTimeFormatterUtils.long2String(timestamp, formatter2, zoneIdParis));
        assertEquals("2022-06-15 07:06:29", LocalDateTimeFormatterUtils.long2String(timestamp, formatter2, zoneIdLos_Angeles));
    }

    @Test
    @DisplayName("根据字符串解析为时间戳 默认格式 默认时区")
    public void string2longTest1() {
        ZoneId zoneIdShanghai = ZoneId.of("Asia/Shanghai");
        try (MockedStatic<ZoneId> mockedZonedId = Mockito.mockStatic(ZoneId.class)) {
            mockedZonedId.when(ZoneId::systemDefault).thenReturn(zoneIdShanghai);
            assertEquals(1655301989000L, LocalDateTimeFormatterUtils.string2long("2022-06-15 22:06:29"));
        }
    }

    @Test
    @DisplayName("根据字符串解析为时间戳 指定格式 默认时区")
    public void string2longTest2() {
        DateTimeFormatter formatter1 = DateTimeFormatter.ISO_LOCAL_DATE_TIME;
        DateTimeFormatter formatter2 = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
        ZoneId zoneIdShanghai = ZoneId.of("Asia/Shanghai");
        long timestamp1 = 1655301989483L;
        long timestamp2 = 1655301989000L;
        String dateStringShanghai1 = "2022-06-15T22:06:29.483";

        String dateStringShanghai2 = "2022-06-15 22:06:29";
        try (MockedStatic<ZoneId> mockedZonedId = Mockito.mockStatic(ZoneId.class)) {
            mockedZonedId.when(ZoneId::systemDefault).thenReturn(zoneIdShanghai);
            assertEquals(timestamp1, LocalDateTimeFormatterUtils.string2long(dateStringShanghai1, formatter1));
            assertEquals(timestamp2, LocalDateTimeFormatterUtils.string2long(dateStringShanghai2, formatter2));
        }
    }

    @Test
    @DisplayName("根据字符串解析为时间戳 默认格式 指定时区")
    public void string2longTest3() {
        ZoneId zoneIdShanghai = ZoneId.of("Asia/Shanghai");
        ZoneId zoneIdMoscow = ZoneId.of("Europe/Moscow");
        ZoneId zoneIdParis = ZoneId.of("Europe/Paris");
        ZoneId zoneIdLos_Angeles = ZoneId.of("America/Los_Angeles");

        String dateStringShanghai2 = "2022-06-15 22:06:29";
        String dateStringMoscow2 = "2022-06-15 17:06:29";
        String dateStringParis2 = "2022-06-15 16:06:29";
        String dateStringLos_Angeles2 = "2022-06-15 07:06:29";

        long timestamp2 = 1655301989000L;

        assertEquals(timestamp2, LocalDateTimeFormatterUtils.string2long(dateStringShanghai2, zoneIdShanghai));
        assertEquals(timestamp2, LocalDateTimeFormatterUtils.string2long(dateStringMoscow2, zoneIdMoscow));
        assertEquals(timestamp2, LocalDateTimeFormatterUtils.string2long(dateStringParis2, zoneIdParis));
        assertEquals(timestamp2, LocalDateTimeFormatterUtils.string2long(dateStringLos_Angeles2, zoneIdLos_Angeles));
    }

    @Test
    @DisplayName("根据字符串解析为时间戳 指定格式 指定时区")
    public void string2longTest4() {
        DateTimeFormatter formatter1 = DateTimeFormatter.ISO_LOCAL_DATE_TIME;
        DateTimeFormatter formatter2 = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");

        ZoneId zoneIdShanghai = ZoneId.of("Asia/Shanghai");
        ZoneId zoneIdMoscow = ZoneId.of("Europe/Moscow");
        ZoneId zoneIdParis = ZoneId.of("Europe/Paris");
        ZoneId zoneIdLos_Angeles = ZoneId.of("America/Los_Angeles");

        String dateStringShanghai1 = "2022-06-15T22:06:29.483";
        String dateStringMoscow1 = "2022-06-15T17:06:29.483";
        String dateStringParis1 = "2022-06-15T16:06:29.483";
        String dateStringLos_Angeles1 = "2022-06-15T07:06:29.483";

        String dateStringShanghai2 = "2022-06-15 22:06:29";
        String dateStringMoscow2 = "2022-06-15 17:06:29";
        String dateStringParis2 = "2022-06-15 16:06:29";
        String dateStringLos_Angeles2 = "2022-06-15 07:06:29";

        long timestamp1 = 1655301989483L;
        long timestamp2 = 1655301989000L;

        assertEquals(timestamp1, LocalDateTimeFormatterUtils.string2long(dateStringShanghai1, formatter1, zoneIdShanghai));
        assertEquals(timestamp1, LocalDateTimeFormatterUtils.string2long(dateStringMoscow1, formatter1, zoneIdMoscow));
        assertEquals(timestamp1, LocalDateTimeFormatterUtils.string2long(dateStringParis1, formatter1, zoneIdParis));
        assertEquals(timestamp1, LocalDateTimeFormatterUtils.string2long(dateStringLos_Angeles1, formatter1, zoneIdLos_Angeles));

        assertEquals(timestamp2, LocalDateTimeFormatterUtils.string2long(dateStringShanghai2, formatter2, zoneIdShanghai));
        assertEquals(timestamp2, LocalDateTimeFormatterUtils.string2long(dateStringMoscow2, formatter2, zoneIdMoscow));
        assertEquals(timestamp2, LocalDateTimeFormatterUtils.string2long(dateStringParis2, formatter2, zoneIdParis));
        assertEquals(timestamp2, LocalDateTimeFormatterUtils.string2long(dateStringLos_Angeles2, formatter2, zoneIdLos_Angeles));
    }
}

源码地址-github

源码地址-gitee

更多文章

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

如若内容造成侵权/违法违规/事实不符,请联系我们进行投诉反馈qq邮箱809451989@qq.com,一经查实,立即删除!

相关文章

100359.统计X和Y频数相等的子矩阵数量

1.题目描述 给你一个二维字符矩阵 grid&#xff0c;其中 grid[i][j] 可能是 X、Y 或 .&#xff0c;返回满足以下条件的子矩阵数量&#xff1a; 包含 grid[0][0]X 和 Y 的频数相等。至少包含一个 X。 示例 1&#xff1a; 输入&#xff1a; grid [["X","Y",…

算法刷题笔记 滑动窗口(C++实现,非常详细)

文章目录 题目描述基本思路实现代码 题目描述 给定一个大小为n ≤ 10^6的数组。有一个大小为k的滑动窗口&#xff0c;它从数组的最左边移动到最右边。你只能在窗口中看到k个数字。每次滑动窗口向右移动一个位置。以下是一个例子&#xff1a; 该数组为 [1 3 -1 -3 5 3 6 7]&…

leetcode 66. 加一

leetcode 66. 加一 题解 刚开始只是以为在最后一位上加一就可以了 &#xff0c; 没想到还有进位呢&#xff0c; 比如说9的话&#xff0c; 加上1就是10&#xff0c; 返回的数组就是[1. 0],把进位的情况考虑进去就可以了。 class Solution { public:vector<int> plusOne(…

Vue3+.NET6前后端分离式管理后台实战(二十八)

1&#xff0c;Vue3.NET6前后端分离式管理后台实战(二十八)

Raw Socket(一)实现TCP三次握手

实验环境&#xff1a; Windows物理机&#xff1a;192.168.1.4 WSL Ubuntu 20.04.6 LTS&#xff1a;172.19.32.196 Windows下的一个http服务器&#xff1a;HFS&#xff0c;大概长这个样子&#xff1a; 客户端就是Ubuntu&#xff0c;服务端就是这个…

[图解]SysML和EA建模住宅安全系统-12-内部块图

1 00:00:00,580 --> 00:00:02,770 接下来我们来画流了 2 00:00:03,100 --> 00:00:05,050 首先第一个是站点状态 3 00:00:05,140 --> 00:00:08,130 从这里到这里&#xff0c;我们画一个过来 4 00:00:10,290 --> 00:00:11,890 这里流到这里 5 00:00:11,900 -->…

多粒度封锁-封锁粒度、多粒度封锁模式

一、引言 1、若采用封锁技术实现并发控制&#xff0c;事务在访问数据库对象前要在数据库对象上加锁&#xff0c;为提高事务的并发程度&#xff0c;商用DBMS会采用一种多粒度封锁方法 2、事务可访问的数据库对象可以是逻辑单元&#xff0c;包括关系、关系中的元组、关系的属性…

Python学习笔记31:进阶篇(二十)pygame的使用之图形绘制

前言 基础模块的知识通过这么长时间的学习已经有所了解&#xff0c;更加深入的话需要通过完成各种项目&#xff0c;在这个过程中逐渐学习&#xff0c;成长。 我们的下一步目标是完成python crash course中的外星人入侵项目&#xff0c;这是一个2D游戏项目。在这之前&#xff…

Debezium报错处理系列之第111篇:Can‘t compare binlog filenames with different base names

Debezium报错处理系列之第111篇:Cant compare binlog filenames with different base names 一、完整报错二、错误原因三、解决方法Debezium从入门到精通系列之:研究Debezium技术遇到的各种错误解决方法汇总: Debezium从入门到精通系列之:百篇系列文章汇总之研究Debezium技…

论文辅助笔记:ST-LLM

1 时间嵌入 2 PFA&#xff08;Partial Frozen Architecture&#xff09; 3 ST_LLM 3.1 初始化 3.2 forward

蓝桥杯开发板STM32G431RBT6高阶HAL库学习FreeRtos——FreeRTOS任务调度方式

一、任务调度方式 1.1抢占式调度&#xff08;不同优先级&#xff09; 主要是针对优先级不同的任务&#xff0c;每个任务都有一个优先级&#xff0c; 优先级高的任务可以抢占优先级低的任务。1.2时间片调度&#xff08;同优先级&#xff09; 主要针对优先级相同的任务&#x…

视频技术助力智慧城市一网统管:视频资源整合与智能化管理

随着信息技术的飞速发展&#xff0c;智慧城市已成为现代城市发展的重要方向。在智慧城市建设中&#xff0c;一网统管作为城市管理的重要策略&#xff0c;通过整合各类信息资源&#xff0c;实现资源的优化配置和问题的快速响应。其中&#xff0c;视频技术作为一网统管场景中的关…

【Linux系统】动态库和静态库 动态库加载

认识动态库静态库 我们有没有使用过库呢&#xff1f;-- 用过c、c的标准库 c的各种函数&#xff0c;c的各种STL容器&#xff0c;我们使用他们内部必须得有具体实现。 Linux: .so(动态库) .a(静态库) Windows: .dll(动态库) .lib(静态库) 库是拿来给别人使用的&#xff0c;所…

sd调试记录:

现象&#xff1a;SDIO读取TF卡&#xff0c;&#xff11;bit模式正常&#xff08;一切操作都正常&#xff09;&#xff0c;4bit模式无法读取&#xff1a; 比如在使用函数f_opendir(&DirInf, SDPath)、f_open(&SDFile, path, FA_CREATE_ALWAYS | FA_WRITE)函数时会出现错…

局部静态变量实现的单例存在多个对象

文章目录 背景测试代码运行测试尝试打开编译器优化进一步分析 背景 业务中出现日志打印失效&#xff0c;发现是因为管理日志对象的单例在运行过程中存在了多例的情况。下面通过还原业务场景来分析该问题。 测试代码 /* A.h */ #ifndef CALSS_A #define CALSS_A#include <…

如何从 Windows 11/10/8.1/8/7 恢复已删除的视频

意外删除了视频或格式化了 SD 卡/硬盘&#xff1f;没有备份已删除的视频&#xff1f;别担心&#xff0c;我们有解决方案来恢复 Windows 11、10 中已删除的视频并处理这种糟糕的情况。 但在了解如何恢复已删除的视频和视频恢复应用程序之前&#xff0c;请知道 Windows 会为您提…

IDEA与通义灵码的智能编程之旅

1 概述 本文主要介绍在IDEA中如何安装和使用通义灵码来助力软件编程,从而提高编程效率,创造更大的个人同企业价值。 2 安装通义灵码 2.1 打开IDEA插件市场 点击IDEA的设置按钮,下拉选择Plugins,如下: 2.2 搜索通义灵码 在搜索框中输入“通义灵码”,如下: 2.3 安…

【雷丰阳-谷粒商城 】【分布式高级篇-微服务架构篇】【17】认证服务01—短信/邮件/异常/MD5

持续学习&持续更新中… 守破离 【雷丰阳-谷粒商城 】【分布式高级篇-微服务架构篇】【17】认证服务01 环境搭建验证码倒计时短信服务邮件服务验证码短信形式&#xff1a;邮件形式&#xff1a; 异常机制MD5参考 环境搭建 C:\Windows\System32\drivers\etc\hosts 192.168.…

rsyslog日志转发

前言 Rsyslog可用于接受来自各种来源(本地和网络)的输入&#xff0c;转换它们&#xff0c;并将结果输出到不同&#xff08;通过模板和filter过滤&#xff09;的目的地&#xff08;目录文件中&#xff09; rsyslog是一个开源工具&#xff0c;被广泛用于Linux系统以通过TCP/UDP…

树莓派5安装冬瓜HAOS教程

原文来自瀚思彼岸和hasshome 一、安装前准备 &#xff08;1&#xff09;软件 1、树莓派烧录软件Imager 2、冬瓜HAOS镜像 &#xff08;2&#xff09;硬件 1、树莓派5 2、TF卡&#xff08;SanDisk Extreme PRO 64GB U3 A2 V30 4k&#xff09; 3、读卡器 4、键盘和鼠标 5、显…