开发者

strange date from uidatepicker

I use date pick开发者_如何学Pythoner and I set its mode to be

pickerView.datePickerMode = UIDatePickerModeDate ;

when select august 3o, 2011

to display It I use

NSDate * selected = [pickerView date];
NSString * date = [selected description];
DateLabel.text = date;

the output is 2011-08-29 21:00:00:00 + 0000

any suggestion on how to display the correct date only


Have a look at the NSDateFormatter class.

try using:

NSDate *selected = [pickerView date];

NSDateFormatter *formatter = [[NSDateFormatter alloc] init];
[formatter setTimeStyle:kCFDateFormatterNoStyle];
[formatter setDateStyle: kCFDateFormatterShortStyle];

NSString *date = [formatter stringFromDate:selected];
[formatter release];


NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
[dateFormatter setDateFormat:@"DD/MM/yyyy"];//you can change format here @"MM/yyyy"
DateText.text = [dateFormatter stringFromDate:datePicker.date];
[dateFormatter release];
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜