i using code store 2 strings(newcategory & reportdate) in database:
string newcategory = spinnerfood.getselecteditem().tostring(); // create instance of simpledateformat used formatting // string representation of date (month/day/year) dateformat df = new simpledateformat("mm/dd/yyyy hh:mm:ss"); // date today using calendar object. date today = calendar.getinstance().gettime(); // using dateformat format method can create string // representation of date defined format. string reportdate = df.format(today); // preparing post params list<namevaluepair> params = new arraylist<namevaluepair>(); params.add(new basicnamevaluepair("name", newcategory)); params.add(new basicnamevaluepair("dtime", reportdate)); servicehandler serviceclient = new servicehandler(); string json = serviceclient.makeservicecall(url_new_category, servicehandler.post, params); this stores name string successfully. date , time data in database contains value:
0000-00-00 00:00:00
if change date string date/time format so:
df.format(today); params.add(new basicnamevaluepair("dtime", today)); i error:
basicnamevaluepair (string, java.lang.string) in basicnamevaluepair cannot applied
to (string, java.util.date)
could inform me how store date , time value database?
you can add date , time params formatted string
params.add(new basicnamevaluepair("dtime", reportdate)); your code handles db calls use mysql function str_to_date(...) format string datetime required.
Comments
Post a Comment