java - Convert jsonObject Date to string in dd:mm:yyyy format in android -


i getting jsonobject date database

jsondate

"date_of":"\/date(1251763200000)\/" 

method 1

public string getdatefromjson1(string jsondate) {         string timestring = jsondate.substring(jsondate.indexof("(") + 1, jsondate.indexof(")"));         string[] timesegments = timestring.split("\\+");         // may have handle negative timezones         int timezoneoffset = integer.valueof(timesegments[1]) * 36000; // (("0100" / 100) * 3600 * 1000)         int millis = integer.valueof(timesegments[0]);         date time = new date(millis + timezoneoffset);         return new simpledateformat("mm/dd/yyyy hh:mm a").format(time);     } 

method 2

public string getdatefromjson(string jsondate) {         string json = jsondate;         string timestamp = jsondate.split("\\(")[1].split("\\+")[0];         date createdon = new date(long.parselong(timestamp));         system.out.println("createdon---->"+createdon);         system.out.println(new simpledateformat("mm/dd/yyyy hh:mm a").format(createdon));         return new simpledateformat("mm/dd/yyyy hh:mm a").format(createdon);     } 

both time getting same logcat error

java.lang.numberformatexception: invalid long: "1251763200000)/"             @ java.lang.long.invalidlong(long.java)             @ java.lang.long.parse(long.java)             @ java.lang.long.parselong(long.java)             @ java.lang.long.parselong(long.java) 

method 2:

instead of

"string timestamp = jsondate.split("\(")[1].split("\+")[0];"

use "

string timestamp2 = timestamp.split("\(")[1].split("\)")[0];

"


Comments

Popular posts from this blog

html - Outlook 2010 Anchor (url/address/link) -

javascript - Why does running this loop 9 times take 100x longer than running it 8 times? -

Getting gateway time-out Rails app with Nginx + Puma running on Digital Ocean -