Hi all,
as per my object i have some problems using dateFromString that seems returns always a NSDate object null or another date different from the date i'm using.
To set a date on a DataPicker i use the code below:
this is the NSLog result
If use setDateFormat before create myDate, it's always null
this is the result
If i use NSlocale
there isn't effect.
myDate is null if use setDateFormat otherwise the date is wrong.
How can i set a DataPicket using a date of mine?
Ciao,
stè
as per my object i have some problems using dateFromString that seems returns always a NSDate object null or another date different from the date i'm using.
To set a date on a DataPicker i use the code below:
Code:
NSDateFormatter *df = [[NSDateFormatter alloc] init];
NSDate *myDate = [df dateFromString: self.selectedDate];
NSLog(@"data 1 %@", self.selectedDate);
NSLog(@"data 2 %@", myDate);
if (myDate) {
dtpDate.date = myDate;
}
this is the NSLog result
Code:
data 1 2010-05-12 21:45:00
data 2 1970-01-01 01:00:00 +0100
If use setDateFormat before create myDate, it's always null
Code:
NSDateFormatter *df = [[NSDateFormatter alloc] init];
[df setDateFormat:@"yyyy-MM-dd hh:mm"];
NSDate *myDate = [df dateFromString: self.selectedDate];
NSLog(@"data 1 %@", self.selectedDate);
NSLog(@"data 2 %@", myDate);
if (myDate) {
dtpDate.date = myDate;
}
this is the result
Code:
data 1 2010-05-12 21:45:00
data 2 (null)
If i use NSlocale
Code:
NSDateFormatter *df = [[NSDateFormatter alloc] init];
NSLocale *locale = [[NSLocale alloc] initWithLocaleIdentifier:@"en_US"];
[df setLocale:locale];
NSDate *myDate = [df dateFromString: self.selectedDate];
NSLog(@"data 1 %@", self.selectedDate);
NSLog(@"data 2 %@", myDate);
if (myDate) {
dtpDate.date = myDate;
}
there isn't effect.
myDate is null if use setDateFormat otherwise the date is wrong.
How can i set a DataPicket using a date of mine?
Ciao,
stè