简体   繁体   中英

Split parsed text to seperate date and time android

This code:

 else if (tagName.equals(TAG_TIME)) {
      if (item != null) {
           item.mTime_SV = pullParser.getAttributeValue(null, "from");
           System.out.println("time"+ item.mTime_SV);
  }

gives me 2014-06-21T08:00:00

Is there a way to split this parsed text 2014-06-21T08:00:00 into two parts, date and time? Am I using the wrong search criteria, am I to simple or is it just not possible??

just use split to get pieces

Try this

  String date = "2014-06-21T08:00:00";
  String[] parts = date.split("T");
  System.out.println("Date: " + parts[0]);
  System.out.println("Time: " + parts[1]);

or

 String date = "2014-06-21T08:00:00";
 System.out.println("Date: " + date.substring(0, date.indexOf('T')));
 System.out.println("Time: " + date.substring(date.indexOf('T') + 1));

In your case

 else if (tagName.equals(TAG_TIME)) {
      if (item != null) {
           item.mTime_SV = pullParser.getAttributeValue(null, "from");
            String[] parts = item.mTime_SV.split("T");
            System.out.println("Date: " + parts[0]);
            System.out.println("Time: " + parts[1]);
  }

try below code:-

System.out.println("date: " + "2014-06-21T08:00:00".split("T")[0]);
System.out.println("time: " + "2014-06-21T08:00:00".split("T")[1]);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM