Android将UTC /日期(1419969600000 + 0400)/转换为本地日期

时间:2015-05-18 09:04:22

标签: android

我的json输出收到以下响应,在此我必须将 /日期(1419969600000 + 0400)/ 转换为本地日期格式,我已用Google搜索,没有比赛,有人帮忙,提前致谢...

{
        "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"
            }
        ]
    }

2 个答案:

答案 0 :(得分:0)

这是我朋友的代码。即使在夏令时也能正常工作。

public  String getDateCurrentTimeZone(long timestamp) {
        try{
            Calendar calendar = Calendar.getInstance();
            TimeZone tz = TimeZone.getDefault();
            calendar.setTimeInMillis(timestamp * 1000);
            calendar.add(Calendar.MILLISECOND, tz.getOffset(calendar.getTimeInMillis()));
            SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
            Date currenTimeZone = (Date) calendar.getTime();
            return sdf.format(currenTimeZone);
        }catch (Exception e) {
        }
        return "";
    }

答案 1 :(得分:0)

我已经使用了这组代码。现在可以使用,感谢您的帮助。

调用 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 "";
    }
}