0

I want to get the CreateDate value from xml file the xml file is like this way.

<d:CreateDate m:type="Edm.DateTime">2012-03-18T15:11:30.403</d:CreateDate>

I created JSONObject as

JSONObject json=new WCFServices().getWhatsNew();//i get the json object WCFServices class.
JSONArray whatsnew= json.getJSONArray("d");
String CreateDate= c.getString("CreateDate");

if i try to print the value it gives me output as:

 /Date(1330041600000)/

I want to get the value as like 2012-03-18T15:11:30.403 how to get it ?

10
  • Make more clear so we can answer it Commented Mar 31, 2012 at 5:50
  • how can you parse a xml file using JsonArray? Commented Mar 31, 2012 at 5:54
  • cast xml to json first. then get the JsonArray. After getting array, then get the JsonObject from that array by placing Date Commented Mar 31, 2012 at 5:56
  • just want to make sure that output of 2012-03-18T15:11:30.403 is (1330041600000)? or you just post example value? Commented Mar 31, 2012 at 6:02
  • So, you're not getting the right output as /Date(1300....)/. First you need to get the exact value, then I think you need to use SimpleDateFormat class and then pass your timestamp to it it will make it to datetime. Commented Mar 31, 2012 at 6:03

1 Answer 1

1

I think your output is in epoch date format. So you need to convert it to normal date time. Try this for it..

public String normal_date_time(String epoch_date)
    {
      try
      {
         long epoch = Long.parseLong( epoch_date );

         String dateFormat = "dd/MM/yyyy HH:mm:ss.SSS";
         SimpleDateFormat formatter = new SimpleDateFormat(dateFormat);     
         Calendar calendar = Calendar.getInstance();
         calendar.setTimeInMillis(epoch);
         String formated_date =  formatter.format(calendar.getTime()); 
         Log.d("Date", formated_date);
         return formated_date;
      }
      catch (Exception e) 
      {
        // TODO: handle exception
          return null;
      }

You can find more about DateFormat by following links, It will help you to retrieve output in different formats.

http://developer.android.com/reference/java/text/SimpleDateFormat.html

http://developer.android.com/reference/android/text/format/DateFormat.html

Hope this will help you..And don't forget to accept this if it help you.

Thanks...

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.