Skip to content Skip to sidebar Skip to footer

Convert Jsoup Element To String

I'm developing an Android app. I need to change an Element in Jsoup to a string so that I can subtract the two. The code below and String value = valueOf(arrT.val()); do not w

Solution 1:

Use Jsoup text() function

SimpleDateFormatsdf=newSimpleDateFormat("yyyyMMdd HH:mm:ss");
Datedate2= sdf.parse(prdt.text());

Solution 2:

try out:

String value = arrT.val(); SimpleDateFormat sdf = new SimpleDateFormat("HH:mm:ss");

Date date = sdf.parse(value);

see the jsoup apidocs

Note: the date pattern must match with the format you are passing to the parse method.

Additional note: as doc = Jsoup.connect(URL) does network calls, consider putting it in an AsyncTask instead of calling directly on the UI Thread (in the onCreate() method).

Solution 3:

If you are getting date in

Then it should be like this and are you forgetting prdt.val()

SimpleDateFormatsdf=newSimpleDateFormat("yyyyMMdd hh:mm:ss");
Datedate= sdf.parse(prdt.val());

Post a Comment for "Convert Jsoup Element To String"