1

My json output receives the following response, In this I have to convert the /Date(1419969600000+0400)/ to local date format, I have googled for this, nothing matches, someone help, Thanks in advance...

{
        "ErrorCode": 0,
        "ErrorMessage": "",
        "CustomerDueInvoices": [
            {
                "Customer_ID": "00000001",
                "Details": "Bill for The Month of December 2014",
                "DueAmount": 549.31,
                "DueDate": "/Date(1419969600000+0400)/",
                "InvoiceAmount": 549.31,
                "InvoiceDate": "/Date(1419969600000+0400)/",
                "InvoiceNo": "RTDBNWP/201527/14",
                "Property_Code": "WP-A-E003",
                "RevenuHead": "Late Payment Fee -gf"
            },
            {
                "Customer_ID": "00000001",
                "Details": "Bill for The Month of December 2014",
                "DueAmount": 132.03,
                "DueDate": "/Date(1419969600000+0400)/",
                "InvoiceAmount": 132.03,
                "InvoiceDate": "/Date(1419969600000+0400)/",
                "InvoiceNo": "RTDBNWP/201633/14",
                "Property_Code": "WP-A-E003",
                "RevenuHead": "Late Payment Fee"
            }
        ]
    }
arun
  • 3,497
  • 3
  • 14
  • 9

1 Answers1

0

I have used this set of code.It works now, Thanks for all the help.

Call getDate(dateString);

private String getDate(String date) {
    date = date.replace("/", "");
    date = date.replace("(", "");
    date = date.replace(")", "");
    date = date.replace("Date", "");
    date = date.replace("+", "~");
    String[] dateString = date.split("~"); //
    // getDates(Long.parseLong(dateString[0])+Long.parseLong(dateString[1]));
    return getDates(dateString);
}

private String getDates(String[] date) {
    try {
        Calendar calendar = Calendar.getInstance();
        TimeZone tz = TimeZone.getDefault();
        calendar.setTimeInMillis(Long.parseLong(date[0])
                + (Long.parseLong(date[1]) / 1000));
        calendar.add(Calendar.MILLISECOND,
                tz.getOffset(calendar.getTimeInMillis()));
        //SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd hh:mm:ss");
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
        Date currenTimeZone = (Date) calendar.getTime();
        return sdf.format(currenTimeZone);
    } catch (Exception e) {
        return "";
    }
}
arun
  • 3,497
  • 3
  • 14
  • 9