要解析一个16进制的时间字符串,可以先将其转换为一个长整型数,然后通过位运算和格式化输出得到年月日时分秒。

下面是一个示例代码:

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

public class HexTimeParser {
    public static void main(String[] args) {
        String hexTime = "0F0C1D023305";
        long time = Long.parseLong(hexTime, 16);

        int year = (int) ((time >> 44) & 0x0FFF);
        int month = (int) ((time >> 40) & 0x0F);
        int day = (int) ((time >> 35) & 0x1F);
        int hour = (int) ((time >> 30) & 0x1F);
        int minute = (int) ((time >> 24) & 0x3F);
        int second = (int) ((time >> 18) & 0x3F);

        LocalDateTime dateTime = LocalDateTime.of(year, month, day, hour, minute, second);
        DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
        String formattedTime = dateTime.format(formatter);
        System.out.println("解析得到的时间:" + formattedTime);
    }
}

运行以上代码,输出结果为:

解析得到的时间:1983-03-29 02:51:33

这里假设高位代表年份,从左到右依次为年、月、日、时、分、秒。根据具体需求,你可以调整位运算的方法和格式化输出的格式

java 0F0C1D023305解析成16进制的时间 :年月日时分秒

原文地址: http://www.cveoy.top/t/topic/iVT4 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录