ios - UIDatePicker 作为 inputView
<p><p>我在 <code>UIDatePicker</code> 作为 inputView 有两个问题。<br/>
<br/>
<strong>1:</strong>当我在 datePicker 中选择“April 17 9 00 PM”时,<br/>
dateTextField 输出“2014-04-107 21:00:00”。<br/></p>
<p><strong>2:</strong>我国的UTC是+0900。<br/>
但是,<code>NSLog</code> 输出“2014-04-17 12:00:00 +0000”。<br/>
<br/>
我该如何解决这些问题?</p>
<pre><code>@property IBOutlet UITextField* dateTextField;
@property IBOutlet UIDatePicker* datePicker;
@property UIToolbar* toolBar;
- (void)viewDidLoad
{
self.datePicker = [initWithFrame:CGRectMake(0, 600, 320, 216)];
;
self.toolBar = [initWithFrame:CGRectMake(0, -40, 320, 40)];
self.toolBar.barStyle = UIBarStyleBlackOpaque;
UIBarButtonItem* doneButton = [initWithBarButtonSystemItem:UIBarButtonSystemItemDone target:self action:@selector(dateTextFieldShouldReturn)];
NSArray* finishBarItems = ;
;
self.dateTextField = [initWithFrame:CGRectMake(40, 293, 250, 30)];
self.dateTextField.delegate = self;
self.dateTextField.inputView = self.datePicker;
self.dateTextField.inputAccessoryView = self.toolBar;
;
}
- (void)dateTextFieldShouldReturn
{
NSDateFormatter* formatter = [init];
;
NSString* dateString = ;
;
;
NSDate* date = ;
NSLog(@"%@", date);
}
</code></pre></p>
<br><hr><h1><strong>Best Answer-推荐答案</ strong></h1><br>
<p><p>像这样对我有用:</p>
<pre><code>- (void)dateTextFieldShouldReturn
{
NSDateFormatter* formatter = [init];
initWithLocaleIdentifier:@"en_GB"]];
;
NSString* dateString = ;
;
;
NSDate* date = ;
NSLog(@"%@", date);
}
</code></pre></p>
<p style="font-size: 20px;">关于ios - UIDatePicker 作为 inputView,我们在Stack Overflow上找到一个类似的问题:
<a href="https://stackoverflow.com/questions/23132695/" rel="noreferrer noopener nofollow" style="color: red;">
https://stackoverflow.com/questions/23132695/
</a>
</p>
页:
[1]