私は自分でこの問題に取り組んできました。以下は、データベースに日付を挿入するコードです。データベースからの抽出も同様ですが、現在そのための私のコードは乱雑です。基本的に、datepicker からタイムスタンプを作成し、それを文字列として php に送信します。PHP では、次に int に変換し、次に datetime オブジェクトに変換してから挿入します。
おそらくより良い方法ですが、これはうまくいきます。
iPhone用のxcode...
-(void)upload{
NSTimeInterval timeStamp = [self.datePicker.date timeIntervalSince1970];
NSNumber *timeStampObj = [NSNumber numberWithDouble: timeStamp];
self.thisNumber=[timeStampObj stringValue];
NSLog(@"date...%@",thisNumber);
[self postMessage:thisNumber];
}
-(IBAction)push:(id)sender{
[self upload];
}
-(void)postMessage:(NSNumber*)thisNumber {
NSMutableString*postString=[NSMutableString stringWithString:kPostURL];
[postString appendString:[NSString stringWithFormat:@"?%@=%@",kTimestamp,thisNumber]];
[postString setString:[postString stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]];
NSLog(@"postString...%@",postString);
NSMutableURLRequest*request=[[NSMutableURLRequest alloc]initWithURL:[NSURL URLWithString:postString]];
[request setHTTPMethod:@"POST"];
postConnection=[[NSURLConnection alloc]initWithRequest:request delegate:self];
}
php …</p>
$date=$_GET['date'];
$ts=intval($date);
$other=date("Y-m-d H:i:s", $ts);
if(mysql_query("INSERT INTO fifteen VALUES('','$other')"))
echo "successful insert";
else
echo "failed";