I’m receiving a JSON object with date value like this:
{"PostingDate":"\/Date(1325134800000-0500)\/"}
And I want to parse it in Java code to Date or getting it as a String.
I want to know what is the easy way of doing it.
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
I take it the first number (
1325134800000) is the number of milliseconds since epoch, and-0500is the time zone. This appears to be the case given the sample code below, which seems to do what you want.The following code parses the JSON input using Jackson, which I recommend if you don’t have a JSON parsing library of choice yet. It lacks error checking etc.
Sample code:
Output: