开发者

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

开发者 https://www.devze.com 2023-03-13 22:23 出处:网络
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 ca

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

精彩评论

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

关注公众号