Manish Goswami
Manish Goswami

Reputation: 865

Convert Hex to Decimal and Decimal to TimeStamp in JAVA

I have facing Problem in Parsing 16 digit hex string to decimal integer value.

I have tried following code for converting hex to decimal:

    String HexString= "0000113fc208dff"; 
    int dec= Long.parseLong(HexString);

But its throwing NumberFormatException: Invalid int ...

Now How do i Convert to Decimal/Binary and Further Convert Decimal/Binary to Time Stamp ??

Any help would be appreciated.

Upvotes: 0

Views: 2764

Answers (2)

Scary Wombat
Scary Wombat

Reputation: 44854

try this code

String HexString= "0000113fc208dff"; 
long dec= Long.parseLong(HexString, 16);
System.out.println(dec);

Result:

1185345998335  

Upvotes: 2

Patrick Chan
Patrick Chan

Reputation: 1029

The first parameter is the String, second parameter is the radix

long epoch=Long.parseLong(str, 16);

Then convert to Timestamp through Calendar

Calendar c=Calendar.getInstance();
c.setTimeInMillis(epoch);

Upvotes: 3

Related Questions