gpt4 book ai didi

ios - 设置默认时区不成功

转载 作者:行者123 更新时间:2023-11-29 03:42:22 26 4
gpt4 key购买 nike

我使用setDefaultTimezone来设置时区并在UITableview中显示时间和位置。 enter image description here

我使用下面的代码来设置默认时区

[cell.detailTextLabel setText:[NSString stringWithFormat:@"%@", evnt.location]];
[NSTimeZone setDefaultTimeZone:[NSTimeZone timeZoneWithName:evnt.location]];
[cell.textLabel setText:[NSString stringWithFormat:@"%@",[NSDate date]]];

我必须做什么?

最佳答案

使用 NSCalendar 和 setTimeZone 方法。

  NSDate *newDate;
NSDateComponents *dateComponents = [[NSCalendar currentCalendar] components:~ NSTimeZoneCalendarUnit fromDate:[NSDate date]];

newDate = [[NSCalendar currentCalendar] dateFromComponents:dateComponents];
NSLog(@"newDate: %@", newDate);
NSLog(@"newDate: %.0f", [newDate timeIntervalSinceReferenceDate]);

新日期:2011-09-09 15:02:09 +0000新日期:337273330

  [dateComponents setTimeZone:[NSTimeZone timeZoneWithName:@"Australia/Sydney"]];
newDate = [[NSCalendar currentCalendar] dateFromComponents:dateComponents];
NSLog(@"newDate: %@", newDate);
NSLog(@"newDate: %.0f", [newDate timeIntervalSinceReferenceDate]);

新日期:2011-09-09 00:52:03 +0000新时间间隔:337222930

 [dateComponents setTimeZone:[NSTimeZone timeZoneWithName:@"Europe/Paris"]];
newDate = [[NSCalendar currentCalendar] dateFromComponents:dateComponents];
NSLog(@"newDate: %@", newDate);
NSLog(@"newDate: %.0f", [newDate timeIntervalSinceReferenceDate]);

新日期:2011-09-09 08:52:03 +0000新时间间隔:337251730

关于ios - 设置默认时区不成功,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18224274/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com