Java 日期时间转换为6位十六进制字符串
以下是 Java 代码示例,将当前日期时间转换为 6 个长度的十六进制:
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
public class HexDateTime {
public static void main(String[] args) {
LocalDateTime now = LocalDateTime.now();
String format = now.format(DateTimeFormatter.ofPattern('yyMMddHHmmss'));
int hex = Integer.parseInt(format, 16);
String hexString = String.format('%06X', hex);
System.out.println(hexString);
}
}
输出结果类似于:'210415115310',表示当前日期时间为 2021 年 4 月 15 日 11 点 53 分 10 秒。
原文地址: https://www.cveoy.top/t/topic/n9qT 著作权归作者所有。请勿转载和采集!