私はたDateFormatterで問題を持っています。私は以下のように私のコードを追加します。最後に文字列とnsdateで同じ日付を取得する方法は?
NSDate *currentDate = [NSDate date];
NSLog(@"Current Date: %@",currentDate); //Current Date: 2016-10-14 08:07:15 +0000
NSTimeZone *timeZone = [NSTimeZone localTimeZone];
NSString *tzName = [timeZone name];
NSLog(@"Current TimeZone: %@",tzName); //Current TimeZone: Asia/Kolkata
NSTimeZone *systemTimeZone = [NSTimeZone systemTimeZone];
NSString *SyTZName = [systemTimeZone name];
NSLog(@"System TimeZone: %@",SyTZName); //System TimeZone: Asia/Kolkata
NSString *strCurrentDate = [NSString stringWithFormat:@"%@",[NSDate date]];
NSLog(@"Current Date: %@",strCurrentDate);//Current Date: 2016-10-14 08:07:47 +0000
NSDateFormatter* localDateFrm = [[NSDateFormatter alloc] init] ;
[localDateFrm setTimeZone:[NSTimeZone timeZoneWithName:@"IST"]];
[localDateFrm setDateFormat:@"dd-MM-yyyy hh:mm a"];
NSString* local_string = [localDateFrm stringFromDate:currentDate];
NSLog(@"local_string: %@",local_string);//local_string: 14-10-2016 01:37 PM
NSDateFormatter* local_dateFormatter = [[NSDateFormatter alloc] init] ;
[local_dateFormatter setTimeZone:[NSTimeZone timeZoneWithName:@"IST"]];
[local_dateFormatter setDateFormat:@"dd-MM-yyyy hh:mm a"];
NSDate *date = [local_dateFormatter dateFromString:local_string];
NSLog(@"date : %@",date);//date : 2016-10-14 08:07:00 +0000
私は01:37 PM
を必要とするが、私はその私が回答(1:37 PM)を期待与えないNSDateに文字列を変換.when私は08:07:00 +0000
を取得します。時間は違います。 ですので、これを手伝ってください。おかげさまで
'2016年10月14日午前8時07分00秒+ 0000のような通知のためにも
timezone
を設定することができます2つ目は' 2016年10月14日午前13時37分に等しいです: 00 + 0330'(または-0330、私は決して知らない、NSDateとして)。 – Larme
'NSDate'はGMT形式です(私は思う)、文字列に変換すると変換されるのは – Tj3n
です。それは正しい答えですが、同じ文字列をnsdateに変換するとその文字列が変更されます。実際に私はこのnsdateをUIlocalnotification.firedateに使用する必要があります。 –