android - java.sql.Timestamp cannot be cast to net.sourceforge.jtds.jdbc.DateTime -


i tying cast datetime sql server timestamp got error don't know did wrong. know how solve this? :

this java/android error :

fatal exception: main process: abtech.waiteriano.com.waitrer, pid: 29858 java.lang.classcastexception:
java.sql.timestamp cannot cast net.sourceforge.jtds.jdbc.datetime

i have timestamp "2017-04-05 19:37:47:54" , value cannot casted above error java datetime object.

and error originates part of c# code (in sql server database) :

systime = (((datetime) dtchecks.get("openin").get(0)).totime().gethours() * 60) +  ((datetime) dtchecks.get("openin").get(0)).totime().getminutes(); 

the value of systime date "2017-04-05 19:37:47.54". retrieved making toast...

toast.maketext(context,dtchecks.get("openin").get(0) + "", toast.length_long).show(); 

if can timestamp c# java , have (cast) java string code example code should :

first declare variables :

static date myjavadate; //create (java) date object static dateformat dateform; //will setup match incoming c# time format  static string str_ts; //string holds c# timestamp 

then in main part of code :

//# set match incoming time/date format dateform = new simpledateformat("yyyy-mm-dd hh:mm:ss:sss");  //# set input timestamp date convert str_ts = "2017-04-05 19:37:47:54"; //srt_ts = c_sharp_timestamp.tostring(); //untested  //# convert via function check result myjavadate = convertstringtodate(str_ts); system.out.println("myjavadate : " + myjavadate); 

below supporting convertstringtodate function :

public static date convertstringtodate(string input)  {     try { date date = (date) dateform.parse(input); return date; }      catch (parseexception exc) { system.out.println("date converting error : " + exc); return null; } } 

checking println result, should :

myjavadate : wed apr 05 19:37:47 utc 2017 


note: notice simpledateformat("yyyy-mm-dd hh:mm:ss:sss") has required - , : symbols , space @ correct positions match exact same style of c# timestamp format? aware if part wrong fails convert date... for example : if string 05/04/2017... declare ("dd/mm/yyyy... , on success.

also sss milliseconds date ignores part anyway.


Comments