Java Long Number Readable Format toStringLong(long id)

Here you can find the source of toStringLong(long id)

Description

to String Long

License

Open Source License

Declaration

public static String toStringLong(long id) 

Method Source Code


//package com.java2s;
//License from project: Open Source License 

import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.Date;

public class Main {
    private static final long xFFFFFF = 0xFFFFFF;
    private static final int xFF = 0xFF;
    private static final DateFormat SDF_MED = SimpleDateFormat.getDateTimeInstance( //
            SimpleDateFormat.MEDIUM, //
            SimpleDateFormat.MEDIUM);

    public static String toStringLong(long id) {
        long time = (System.currentTimeMillis() >> 42 << 42) + (id >> 22);
        long inc = (id >> 8) & xFFFFFF;
        long instanceId = id & xFF;

        return id + " (DEC)"//
                + "\n" + toString(id) + "  (HEX)" //
                + "\ntime=" + SDF_MED.format(new Date(time)) + ", instanceId=" + instanceId + ", inc=" + inc;
    }//from   ww w  . jav a2 s  . co m

    public static String toString(long id) {
        String hex = Long.toHexString(id);
        return hex.subSequence(0, 8) //
                + "-" + hex.substring(8, 14) //
                + "-" + hex.substring(14);
    }
}

Related

  1. toLocalizedInteger(long value)
  2. toMB(long b)
  3. toMB(long bytes)
  4. toReadableBytes(long bytes)
  5. toReadableNumber(long number)