NSDatePicker
Hi there,
I have a problem of extracting time from the datepicker box. I setup time show in the datepicker box as 1982-10-12 16:00:00 +0000, when I use substringWithRange:NSMakeRange(10,10) to extract the string of time, I got 16:00:00, when I try to convert the string to integer, I got 16, but I can not get the minute and second value. Does anyone have an idea?
Well you could use a scanner to parse the string and decode it. That's rather ugly. Apple provide very good functions for converting strings to dates. However I wouldn't expect to even use them. I feel confident (although I've never the date picker) that the control will give you a date or time object or something. I see to recall that the date picker is rather basic - it's just up/down arrows really and doesn't provide a popup calendar or anything fancy. I'm sure with a little googleing you'll find something really useful. If you're still stuck at the weekend, I'll take a closer look at this for you.
Thanks for the advise, I used scanf to retrieve data from the datepicker, it works, not smart, but works :)
Another question, how could I set the default date in the NSDatePicker box as today? Couldn't find a solution on internet, maybe can someone give me a good reference link? Thanks
jz45 try this :
// Create todays dateNSDate *todayDate = [NSDate date];
// use the todayDate as the newStartDate
[self setDateValue:todayDate]
this will set the date pickers value to today every time it program starts
subclass the a NSDatePicker and add this code to the -(void)awakeFromNib{}
^^ it works for me ^^
It doesn't work :( it says setDateValue may not work for GuiController, which is my nib name