开发者

Is there a way i can assign the value shown by the date picker widget to a variable of type "Date"?

I'm creating an app for the android OS that allows the user to pick a Date. I want开发者_如何学JAVA to be able to store the date the User picks in a mm/dd/yy form . I know there is a variable type called date. How do i assign the value shown by the picker to the date variable ?


You could use a Time variable :

Time t = new Time();
t.dayOfMonth = dialog.getDayOfMonth();
t.month = dialog.getMonth();
t.year = dialog.getYear();
t.normalize( false );

and then use a simple date formatter or the format method of Time to format it in mm/dd/yy

String s  = t.format( "your pattern" );


You might get it in String type just parse it to Date using SimpleDateFormat

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜