Date format retrieved from a service

This question already has an answer here:

  • How do I format a Microsoft JSON date? 37 answers

  • This is the MS JSON date format.

    Use:

    var myDate = new Date(parseInt(String(dateString).substr(6)));
    

        String mDate = getFormattedDate(e.getString("JSON OBJECT"));
    
        private String getFormattedDate(String stringDate) throws JSONException {
        String strDate = stringDate.replace("/Date(", "").replace(")/", "");
    
        strDate = strDate.substring(0, strDate.indexOf("+"));
        Long longDate = Long.parseLong(strDate, 10);
        Date mDate = new Date(longDate);
    
        SimpleDateFormat sdf = new SimpleDateFormat("MMM dd, yyyy");
        String formattedDate = sdf.format(mDate);
    
        return formattedDate;
    }
    
    链接地址: http://www.djcxy.com/p/8164.html

    上一篇: 如何将毫秒转换为日期

    下一篇: 从服务中检索日期格式