Convert JSON dates in the format "mm dd yyyy"

In my application, the Day Fiend JSON response comes as follows:

"CreatedOn": "\/Date(1313572467987+0000)\/" 

I want to convert this date to "MM DD YYYY" format. How can i convert this?

+6
source share
2 answers

This date in the JSON response looks like a standard timestamp (e.g., the number of milliseconds since January 1, 1970). If you parse the timestamp, for example:

  String timestamp = jsonValue.split("\\(")[1].split("\\+")[0]; Date createdOn = new Date(Long.parseLong(timestamp)); 

Now you can use SimpleDateFormat to format the date string:

  SimpleDateFormat sdf = new SimpleDateFormat("MM dd yyyy"); String formattedDate = sdf.format(createdOn); 

This ignores the time zone setting in this answer ("+0000"), you can also analyze this value and add / remove hours from your timestamp value before formatting.

+7
source

you can use SimpleDateFormat , so try searching the same way.

Detailed example: http://www.helloandroid.com/tutorials/date-handling-android-development

+1
source

Source: https://habr.com/ru/post/895308/


All Articles