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/fhCU 著作权归作者所有。请勿转载和采集!