我正在尝试用时区格式将本地日期时间转换为拉斯维加斯日期时间。
NSDateFormatter *dateFormatterdatabase = [[NSDateFormatter alloc] init];
dateFormatterdatabase=[[NSLocale alloc] initWithLocaleIdentifier:@"en_US_POSIX"];
[dateFormatterdatabase setDateFormat:@"dd-MM-yy hh:mm a"];
NSDate *StarEvent = [[NSDate alloc] init];
StarEvent = [dateFormatterdatabase dateFromString:@"15-05-15 12:00 AM"];
如何将本地时区日期时间格式转换为拉斯维加斯时区格式日期时间。??
例如,这里的当前时间是2015-05-26 11:21:00 IST到LAS VEGAS格式为2015-05-26 22:52:36 PDT.
如何?
// *** Set your Destination TimeZone, for Las Vegas its 'PDT/PST, change TimeZone accordingly for other conversions ***'
NSTimeZone* destinationTimeZone = [NSTimeZone timeZoneWithAbbreviation:@"PST"];
// *** Its your current system(device) time zone ***
NSTimeZone* sourceTimeZone = [NSTimeZone systemTimeZone];
// *** Set your date to convert ***
NSDate *currentDate = [NSDate date];
// *** Calc time difference ***
NSInteger sourceGMTOffset = [sourceTimeZone secondsFromGMTForDate:currentDate];
NSInteger destinationGMTOffset = [destinationTimeZone secondsFromGMTForDate:currentDate];
NSTimeInterval interval = destinationGMTOffset - sourceGMTOffset;
// *** set current real date ***
NSDate* date = [[NSDate alloc] initWithTimeInterval:interval sinceDate:currentDate];
// *** Set Date Formater ***
NSDateFormatter *df = [[NSDateFormatter alloc] init];
[df setTimeZone:destinationTimeZone];
[df setDateStyle:NSDateFormatterShortStyle];
[df setTimeStyle:NSDateFormatterFullStyle];
NSLog(@"Converted Date %@",[df stringFromDate:date]);