나는 날짜가 많이 작동하는 응용 프로그램을 개발하고이 방법을 사용하여 핵심 데이터의 문자열로 다음을 저장합니다 날짜 작업NSRepublicOfChinaCalendar와 NSGregorianCalendar의 차이점은 무엇입니까?
- (NSDate*) stringToDate{
NSDateFormatter *dateFormat = [[NSDateFormatter alloc] init];
[dateFormat setDateFormat:@"yy-MM-dd HH:mm"];
NSDate *date = [dateFormat dateFromString:self];
return date;
}
을/시간은 매우 까다 롭습니다 - 혼자 시간 시스템과 지역 시간의 차이 - 어쨌든 위의 방법은이를 처리해야합니다. 많은 계산이 같은도 있습니다
(A는 NSString에있는 NSDate를 포맷하면 대신 내 경우에는 2 시간 차이를 보여줍니다 디버거에서있는 NSDate 변수를 보는 올바른 현지 시간을 반환하기 때문에 그래서, 희망) :
NSCalendar *calendar = [NSCalendar currentCalendar]; <------
NSDateComponents *components = [calendar components:(NSHourCalendarUnit | NSMinuteCalendarUnit | NSYearCalendarUnit |NSMonthCalendarUnit|NSDayCalendarUnit) fromDate:someDate];
NSInteger now_hour = [components hour];
NSInteger now_minute = [components minute];
NSInteger yearx = [components year];
NSInteger monthx = [components month];
NSInteger dayx = [components day];
특정 날짜/시간을 설정/변경/생성하고, 계산을 수행하고, NSString으로 핵심 데이터에서 다시 검색/저장해야합니다.
제 질문은 적절한 달력을 사용하는 것입니다.
나는 항상 작성해야 :
NSCalendar *calendar = [NSCalendar currentCalendar]; ?
또는
NSCalendar *calendar = [[NSCalendar alloc] initWithCalendarIdentifier:NSGregorianCalendar];
및 ESP
NSCalendar *calendar = [[NSCalendar alloc] initWithCalendarIdentifier:NSRepublicOfChinaCalendar];
. 앱이 유럽/미국 대 중국에서 사용되는지 여부에 따라?
doc에서 따옴표 : '중국 달력을 만들 수 있고 그 달력으로 계산할 수 있지만 필요한 기본 기능이 아직 제대로 작동하지 않아 서식 지정에 사용하면 안됩니다.' – nhahtdh