現在作業中のアプリケーションは iPhone アプリで、バックエンドは .Net にあります。iPhone アプリケーションは、WCF RestFul API を使用します。サーバーが使用しているデータベースは MS SQL であり、客観的 c(xcode4.5,iOS6) のクライアント側です。サーバー側に smallDateTime の形式で日付を保存します。この日付を JSON 形式に戻すときに、以下のコードを使用して NSDate に変換します。以下は、サーバーから受け取るサンプルの日付文字列です (serverDate=/Date(1356527635798+0500)/)。
以下は、変換のための iPhone 側のコードです。
+ (NSDate *)convertServerDateToNSDate:(NSString *)serverDate
{
serverDate = [serverDate stringByReplacingOccurrencesOfString:@"\"" withString:@""];
serverDate = [serverDate stringByReplacingOccurrencesOfString:@"\\" withString:@""];
if(serverDate == nil)
return nil;
NSDate * nsDate;
NSCharacterSet * tempSet1 = [NSCharacterSet characterSetWithCharactersInString:@"("];
serverDate = [serverDate stringByReplacingOccurrencesOfString:@"-" withString:@"+"];
NSCharacterSet * tempSet2 = [NSCharacterSet characterSetWithCharactersInString:@"+"];
NSRange startRange = [serverDate rangeOfCharacterFromSet:tempSet1];
NSRange endRange = [serverDate rangeOfCharacterFromSet:tempSet2];
NSRange actualRange;
actualRange.location = startRange.location + 1;
actualRange.length = endRange.location - actualRange.location;
NSString * tempString = [serverDate substringWithRange:actualRange];
double timeInSecs = [tempString doubleValue]/1000;
nsDate = [NSDate dateWithTimeIntervalSince1970:timeInSecs];
return nsDate;
}
日付変換は iOS-Simulator 6.0 では完璧ですが、ipod では日付が 1 日短く変換されます。私はそれを検索して自分でやろうとしましたが、実際の日付よりも1日少なくなるたびに.
1) 問題は何ですか?
2) どうすれば解決できますか?
3) シミュレーターと iPod の両方でロケールが同じであることを確認しました。
これについての助けは大歓迎です。