I want to convert date time object in java to json string in format as below:
{"date":"/Date(18000000+0000)/"}
I did like this but it didn’t give me the format i desired:
JSONObject object = new JSONObject();
object.put("date",new Date());
and the result of object.toString()
{"date":"Fri May 04 11:22:32 GMT+07:00 2012"}
i want the string “Fri May 04 11:22:32 GMT+07:00 2012” transform to “/Date(18000000+0000)/” (18000000+0000 here is just a example).
Thanks for your help.
The date format that you want is
/Date(<epoch time><Time Zone>)/.You can get the epoch time in java using
long epoch = System.currentTimeMillis()/1000;(found at this link) and the time zone you can get by using the date and time patteren asZ. Then combine all the strings into one and store it to the Json Object.Other possibility is that the time you are getting from iOS device may be of the pattern
yyMMddHHmmssZas got from here. Check the output on the iOS device at different times and identify the correct pattern.