views:

391

answers:

4

hi all, I need to cut off the time from the datepicker data. when i try to set the date as a label, the time is also appending to it. is there any way to cut off the time part from the picker data string. please help. Thanks in advance.

A: 

How are you formatting the the datepicker data? And are you using this constant UIDatePickerModeDate? There are a lot of ways to format the data. Show me what you are doing currently so I can tell you how to trim the time off.

mahboudz
A: 

I recommend you take a look at the NSDateFormatter object. I've used this several times to format the results of my date picker.

mhunter007
A: 

You might want to try something like this:

NSDateFormatter *dateFormatter = [[[NSDateFormatter alloc] init] autorelease]; [dateFormatter setDateStyle:NSDateFormatterMediumStyle]; [dateFormatter setTimeStyle:NSDateFormatterNoStyle];

textLabel.text = [dateFormatter stringFromDate:picker.date];

NSDateFormatter allows you to format any date according to the current language. See the documentation for detail on which styles are available. To disable time use setTimeSytle with NSDateForammterNoStyle (see example).

sliver
A: 

Hi all, I got it working.

-(IBAction) timerButtonPressed:(id)sender
{
NSDate *newDate = [datePicker date];
NSDateFormatter *format = [[NSDateFormatter alloc] init];
[format setDateFormat:@"HH:mm"];
dateField.text = [format stringFromDate:newDate];
}

Thanks for your information.

Shibin Moideen