Skip to content

Conversation

@boycehe
Copy link

@boycehe boycehe commented Apr 13, 2018

when call -(NSString *)formattedDateWithFormat:(NSString *)format in multi thread the result may be error for example:

for (NSInteger index = 0; index < 1000; index++) {

if (index % 2 ==0) {
  [NSThread detachNewThreadWithBlock:^{
   NSLog(@"test1:%@",[[NSDate date] formattedDateWithFormat:@"yyyy-MM-dd"]);
  }];
}else{
  [NSThread detachNewThreadWithBlock:^{
     NSLog(@"test2:%@",[[NSDate date] formattedDateWithFormat:@"yyyy-MM-dd HH:mm:ss.SSS"]);
  }];
}

}

the results is:

2018-04-13 14:07:14.355993+0800 TestDemo_Example[21257:35085629] test1:2018-04-13
2018-04-13 14:07:14.422793+0800 TestDemo_Example[21257:35085632] test2:2018-04-13
2018-04-13 14:07:14.422932+0800 TestDemo_Example[21257:35085631] test1:2018-04-13
2018-04-13 14:07:14.423280+0800 TestDemo_Example[21257:35085633] test1:2018-04-13 14:07:14.354
2018-04-13 14:07:14.423508+0800 TestDemo_Example[21257:35085634] test2:2018-04-13 14:07:14.354
2018-04-13 14:07:14.424189+0800 TestDemo_Example[21257:35085635] test1:2018-04-13 14:07:14.354
2018-04-13 14:07:14.424334+0800 TestDemo_Example[21257:35085637] test1:2018-04-13 14:07:14.354
2018-04-13 14:07:14.424579+0800 TestDemo_Example[21257:35085638] test2:2018-04-13

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant