android - How to remove date from DatePicker toString method? -


i have started learning android through android's big nerd ranch guide. have written simple program in android let's user select date. while printing date using getdate().tostring() method, getting time. want remove time column. far, have tried passing datepicker, date, month, or year through intent, not working. code datepicker looks like:

public dialog oncreatedialog(bundle savedinstancestate)     {        // super.oncreate(savedinstancestate);         date=(date) getarguments().getserializable(extra_tag);         calendar calendar=calendar.getinstance();         calendar.settime(date);         int year=calendar.get(calendar.year);         int month=calendar.get(calendar.month);         int day=calendar.get(calendar.day_of_month);          view view=getactivity().getlayoutinflater().inflate(r.layout.date_picker, null);          datepicker datepicker= (datepicker) view.findviewbyid(r.id.date_button);         datepicker.init(year, month, day, new datepicker.ondatechangedlistener() {             @override             public void ondatechanged(datepicker view, int year, int monthofyear, int dayofmonth) {                 date=new gregoriancalendar(year,monthofyear,dayofmonth).gettime();                 getarguments().putserializable(extra_tag,date);             }         });         return new alertdialog.builder(getactivity()).setview(view).settitle(r.string.date_picker).setpositivebutton(android.r.string.ok, new dialoginterface.onclicklistener() {             @override             public void onclick(dialoginterface dialog, int which) {                 sendresult(activity.result_ok);             }         }).create();     }     private void sendresult(int resultcode)     {         if(gettargetfragment()==null)         {             return;         }         intent i=new intent();         i.putextra(extra_tag,date);         gettargetfragment().onactivityresult(gettargetrequestcode(),resultcode,i);      } 

here's calling activity looks like:

public void onactivityresult(int requestcode, int resultcode,intent data) {     if(resultcode!= activity.result_ok)         return;     if(requestcode==request_code)     {         date date=(date) data.getserializableextra(extra_tag);         crime.setdate(date);         datebutton.settext(crime.getdate().tostring());     } } 

for instance, sample output looks fri jul 17 22:46:42 cdt 2015. motive display date removing time. please explain in detail. thank you

you can convert date writing 2 lines

for example

simpledateformat sdf = new simpledateformat("yyyy-mm-dd");  // set date format string currentdata = sdf.format(date); 

Comments

Popular posts from this blog

qt - Using float or double for own QML classes -

Create Outlook appointment via C# .Net -

ios - Swift Array Resetting Itself -