문제
이 NSString
와 같은 05/09/2015
가 있습니다. 그런 다음 2014-07-28 18:30:00 +0000
두 번째 날짜는 시스템 날짜에서 얻은 것입니다.그 날짜는 Tapku
Calender에 멋지게 배치 될 수 있습니다.그러나 내 문자열이 첫 번째입니다.나는 시스템 날짜에서 얻는 날짜 형식으로만큼 첫 번째 날짜를 변환하고 싶습니다.어떻게 할 수 있습니까?
제발 도와주세요.감사합니다
해결책
nsstring nsdate
NSString *dateString = @"01-02-2010";
NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
// this is imporant - we set our input date format to match our input string
// if format doesn't match you'll get nil from your string, so be careful
[dateFormatter setDateFormat:@"dd-MM-yyyy"];
NSDate *dateFromString = [[NSDate alloc] init];
// voila!
dateFromString = [dateFormatter dateFromString:dateString];
NSDateFormatter *otherFormatter = [[NSDateFormatter alloc] init];
[otherFormatter setDateFormat:@"yyyy-MM-dd"];
//[otherFormatter setTimeStyle:NSDateFormatterMediumStyle];
NSString *resultString = [otherFormatter stringFromDate:dateFromString];
NSLog(@"%@", resultString);
.
를 누른 다음 NSDate로 다시 변환하거나 NSString으로 유지할 수 있습니다.
이 : 여기를 클릭하십시오
제휴하지 않습니다 StackOverflow