2009-10-26 13 views
14

ho bisogno di recuperare la data da un UIDatePicker (preferibilmente vorrei anche essere specificare il formato pure. Per esempio, MMGG sarebbe uscita la stringa 1209. Ogni stringa che ragionevolmente analizzata avrebbe funzionato pure.SDK per iOS: come ottenere la data da un UIDatePicker?

Grazie . in anticipo

risposta

40

è necessario utilizzare la proprietà data:

NSDate *myDate = datePicker.date; 

NSDateFormatter *dateFormat = [[NSDateFormatter alloc] init]; 
[dateFormat setDateFormat:@"cccc, MMM d, hh:mm aa"]; 
NSString *prettyVersion = [dateFormat stringFromDate:myDate]; 

BTW, non è ovvio, ma è possibile aggiungere testo non analizzato specifica che comprende all'interno apici nel formato:

[dateFormat setDateFormat:@"'Game-'yyyyMMdd-HHmm'.xml'"]; 
NSString *filenameVersion = [dateFormat stringFromDate:myDate]; 
+0

Funziona alla grande. Grazie. –

+0

Che cos'è "parsedDate"? – Souljacker

+0

Non sono sicuro, ho aggiornato l'esempio. –

Problemi correlati