Timestamp to date, date formatting string, string to date

Timestamp to date, date formatting string, string to date

1. Install the hutool toolkit

Official document: https://doc.hutool.cn/pages/DateUtil/

<dependency>
    <groupId>cn.hutool</groupId>
    <artifactId>hutool-all</artifactId>
    <version>5.8.16</version>
</dependency>

2. Conversion

import cn.hutool.core.date.DateTime;
import cn.hutool.core.date.DateUtil;

Timestamp to date

DateTime of = DateTime.of(1689782399999l);

date to string

String format = DateUtil.format(of, "yyyy-MM-dd HH:mm:ss.SSS");

string to date

Automatically recognize commonly used formats, such as: 2024-01-02, 2024/01/02, 20240102, etc.

DateTime dateTime1 = DateUtil.parse("2024-01-02 23:59:59.999");

Guess you like

Origin blog.csdn.net/y393016244/article/details/131825028