Skip to content
This repository has been archived by the owner on May 14, 2024. It is now read-only.

squirrel 試用期指定新曆 #29

Open
a8568730 opened this issue May 11, 2020 · 0 comments
Open

squirrel 試用期指定新曆 #29

a8568730 opened this issue May 11, 2020 · 0 comments
Labels
enhancement New feature or request

Comments

@a8568730
Copy link

Xcode iOS ObjectiveC 下的 NSDateFormatter 日期時間

另外,可能一般會比較沒注意到,試著將「西曆」改設定成「日本曆」,這時 dateFormat 的 yyyy 會回傳 0027,而不是西元的 2015! 這代表在日本曆的「平成27年」。
解決的方法就是設定西曆 (NSGregorianCalendar),完整的日期時間取得的程式碼就是如下了。

NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
[dateFormatter setTimeZone:[NSTimeZone timeZoneWithName:@"Asia/Taipei"]];
[dateFormatter setCalendar: [
  [NSCalendar alloc] initWithCalendarIdentifier:NSGregorianCalendar]];
[dateFormatter setDateFormat:@"yyyy/MM/dd HH:mm"];
NSString *todayStr = [dateFormatter stringFromDate:[NSDate date]];
@a8568730 a8568730 added the enhancement New feature or request label May 11, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

1 participant