In my application the Date Fiend JSON response comes as this type:
"CreatedOn": "\/Date(1313572467987+0000)\/"
I want to convert this date in the "MM DD YYYY" format. How can I convert this?
JSON does not have a built-in type for date/time values. The general consensus is to store the date/time value as a string in ISO 8601 format.
JSON does not directly support the date format and it stores it as String. However, as you have learned by now that mongo shell is a JavaScript interpreter and so in order to represent dates in JavaScript, JSON uses a specific string format ISODate to encode dates as string.
That date in your JSON response looks like a standard timestamp (e.g. number of milliseconds since January 1, 1970). If you parse out the timestamp something like:
String timestamp = jsonValue.split("\\(")[1].split("\\+")[0];
Date createdOn = new Date(Long.parseLong(timestamp));
Now you can use SimpleDateFormat to format a date string:
SimpleDateFormat sdf = new SimpleDateFormat("MM dd yyyy");
String formattedDate = sdf.format(createdOn);
This is ignoring the timezone adjustment in that response (the '+0000') you might also want to parse out this value and add/remove the hours from your timestamp value before formatting..
you can use SimpleDateFormat, so just try to search on the same.
Detailed example is here: http://www.helloandroid.com/tutorials/date-handling-android-development
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With