ios - NSDateFormatter 的 NSDate 输出不同
<p><p>我在使用 <code>NSDate</code> 时遇到了一些问题,实际上我只需要它来验证它是否是有效日期,因为如果它是无效日期,则 <code>date</code> 实例将返回零。但是</p>
<pre><code>NSString *textValue = @"13/12/2014";
NSDateFormatter *formatter = [ init];
;
// this should cause the output to have no time
;
formatter.locale = [ initWithLocaleIdentifier:@"en_US"];
initWithCalendarIdentifier:NSGregorianCalendar]];
];
NSDate *date = ;
</code></pre>
<p><code>date</code>的结果是<code>2015-01-12 00:00:00 +0000</code></p>
<p>我期望的结果应该是:<code>nil</code></p></p>
<br><hr><h1><strong>Best Answer-推荐答案</ strong></h1><br>
<p><pre><code>NSString *textValue = @"1/12/2014";
NSString *textValue1 = @"15/12/2014";
NSDateFormatter *formatter = [ init];
;
NSDate *date = ;
NSLog(@" >> %@ ",date);
NSDate *date1 = ;
NSLog(@" >> %@ ",date);
</code></pre></p>
<p style="font-size: 20px;">关于ios - NSDateFormatter 的 NSDate 输出不同,我们在Stack Overflow上找到一个类似的问题:
<a href="https://stackoverflow.com/questions/24134322/" rel="noreferrer noopener nofollow" style="color: red;">
https://stackoverflow.com/questions/24134322/
</a>
</p>
页:
[1]