How to validate string date is in the ISO 8601 date format before applying correct NSDateFormatter?

StackOverflow https://stackoverflow.com/questions/17981358

문제

Remote API's date format is expected to change in the future from the current custom format to ISO 8601. Looking for the efficient way to validate string date format before converting it to the NSDate using proper NSDateFormatter.

도움이 되었습니까?

해결책

The easiest way to validate the format is to actually try converting the string using your date formatter. If it returns nil then the format isn't a match and you can try the other format.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top