java中的时间戳转换(windows 128位系统结构到人类可读格式

时间:2012-05-08 10:29:12

标签: java android

我想转换windows:128位系统结构即..,“D9070B00010002000600090013000000” 以人类可读的格式即..,星期一,2009年11月2日06:09:19所以有算法转换它我没有得到。 for refference http://www.digital-detective.co.uk/freetools/decode.asp其中示例时间和转换时间在java。

提前致谢

1 个答案:

答案 0 :(得分:0)

你包含的格式是某种小端十六进制编码的WORD混乱。看起来非常低效。

但是,它可以像这样解码:

long getSystemStructureTime(String enc) {
    long result = -1L;
    // system time is typically a set of WORDs encoded, little-endian
    if (!TextUtils.isEmpty(enc)) {
        final int length = enc.length();
        ByteBuffer b = ByteBuffer.allocate(length / 2);
        b.order(ByteOrder.BIG_ENDIAN);
        for (int i = 0; i < enc.length(); i+=2) {
            b.put((byte) Integer.parseInt(enc.substring(i, i + 2), 16));
        }
        b.flip();
        b.order(ByteOrder.LITTLE_ENDIAN);
        try {
            int year = b.getShort();
            int month = b.getShort();
            int day = b.getShort();
            int dayOfMonth = b.getShort();
            int hourOfDay = b.getShort();
            int minuteOfHour = b.getShort();
            int secondsOfMinute = b.getShort();
            int millisOfSecond = b.getShort();

            Calendar c = Calendar.getInstance();
            c.set(Calendar.YEAR, year);
            c.set(Calendar.MONTH, month - 1); // months in calendar are base 0
            c.set(Calendar.DAY_OF_MONTH, dayOfMonth);
            c.set(Calendar.HOUR_OF_DAY, hourOfDay);
            c.set(Calendar.MINUTE, minuteOfHour);
            c.set(Calendar.SECOND, secondsOfMinute);
            c.set(Calendar.MILLISECOND, millisOfSecond);

            result = c.getTimeInMillis();
        } catch (BufferUnderflowException e) {
            // This wasn't a proper time..
        }
    }
    return result;
}

填写你发布的内容:

System.out.println(new Date(getSystemStructureTime("D9070B00010002000600090013000000")));

的产率:

Mon Nov 02 06:09:19 GMT+00:00 2009

此版本以毫秒为单位返回时间,根据您的喜好,返回在解析过程中创建的Calendar实例可能会更好。