0
  NSDateFormatter *dateFormat = [[NSDateFormatter alloc] init];
[dateFormat setDateFormat:@"dd-MM-yyyy"];
NSDate *dateInitial = [dateFormat dateFromString:self.labelDateInitial.text];
NSDate *dateEnd = [dateFormat dateFromString:self.labelDateEnd.text];
NSLog(@"%@", dateInitial);
NSLog(@"%@", dateEnd);

为什么我收到 dateInitial 和 dateEnd 的空值?

在标签日期是纯文本

2012 年 11 月 9 日

dd-MM-yyyy 是否正确?

4

1 回答 1

1

If your date string value is nine november 2012 then using dd-MM-yyyy will not help as its expecting date string as 09-11-2012.

For month as november, I think you can use MMMMM, not sure about nine.

i.e. if 09 November 2012 then dd MMMM yyyy can be used.

Edit:

To get the date formatted in specific timezone, set the timezone to the format as below:

   [dateFormat setTimeZone:[NSTimeZone timeZoneWithName:@"UTC"]];

Use appropriated Timezone string e.g. EST, PTC etc.

于 2012-11-09T19:25:46.853 回答