在Mac OS X上,如果轉到系統首選項>日期&時間>打開語言和文本>在頂部單擊格式>,然後使用日曆下拉菜單可以選擇一個coptic日曆。如何在Mac應用程序中顯示此日曆?NSCalendar - 自定義日曆
回答
如何顯示在一臺Mac應用此日曆?
那麼,你是什麼意思顯示?你只是想在計算中使用coptic日曆嗎?如果是這種情況,那麼你所需要的只是一個合適的實例NSCalendar
。由於NSCalendar
(和朋友)由ICU支持,您可以使用任何identifier that ICU supports(在「鍵/類型定義」下)。這意味着你可以選擇其中:
gregorian
- (默認)islamic
- 天文阿拉伯語chinese
- 中國傳統曆法islamic-civil
- 民間(算法)阿拉伯語日曆hebrew
- 傳統希伯來語日曆japanese
- 帝國日曆(與Gregorian exce相同PT爲一年,一個時代的每一個皇帝)buddhist
- 泰國佛曆(同爲公曆除了年)persian
- 波斯日曆coptic
- 科普特歷ethiopic
- 埃塞俄比亞日曆
因此得到NSCalendar
情況下,它會是一個問題的:
NSCalendar *coptic = [[NSCalendar alloc] initWithCalendarIdentifier:@"coptic"];
但是,如果你真的想繪製一些用戶界面(à la iCal),那麼你需要更多的信息。幸運的是,您也可以從NSCalendar
中獲得。
例如,你需要知道日曆多少個月有:
NSRange minMonthRange = [coptic minimumRangeOfUnit:NSMonthCalendarUnit]; // {1,13}
NSRange maxMonthRange = [coptic maximumRangeOfUnit:NSMonthCalendarUnit]; // {1,13}
所以看起來,每年有13個月。好的,一個月的日子怎麼樣?
NSRange minDayRange = [coptic minimumRangeOfUnit:NSDayCalendarUnit]; // {1,5}
NSRange maxDayRange = [coptic maximumRangeOfUnit:NSDayCalendarUnit]; // {1,30}
哇!看起來你可以有一個只有5天的月份! (但是,沒有一個月有30多天)讓我們看看,如果我們可以找到一些:通過20多年
NSDateComponents *firstDayOfMonth = [[NSDateComponents alloc] init];
[firstDayOfMonth setDay:1];
for (NSInteger y = 1500; y < 1520; ++y) {
[firstDayOfMonth setYear:y];
for (NSInteger m = 1; m <= 13; ++m) {
[firstDayOfMonth setMonth:m];
NSDate *date = [coptic dateFromComponents:firstDayOfMonth];
NSRange rangeOfDaysInMonth = [coptic rangeOfUnit:NSDayCalendarUnit inUnit:NSMonthCalendarUnit forDate:date];
NSLog(@"%d - %d => %@", y, m, NSStringFromRange(rangeOfDaysInMonth));
}
}
這種迭代,並建立對應於每月,每年的第一天的NSDate
。然後它會查看當月有多少天,並記錄結果。(注意:1500
和1520
是我挑任意歲)
這將記錄:
1500 - 1 => {1, 30}
1500 - 2 => {1, 30}
1500 - 3 => {1, 30}
1500 - 4 => {1, 30}
1500 - 5 => {1, 30}
1500 - 6 => {1, 30}
1500 - 7 => {1, 30}
1500 - 8 => {1, 30}
1500 - 9 => {1, 30}
1500 - 10 => {1, 30}
1500 - 11 => {1, 30}
1500 - 12 => {1, 30}
1500 - 13 => {1, 5}
1501 - 1 => {1, 30}
1501 - 2 => {1, 30}
1501 - 3 => {1, 30}
1501 - 4 => {1, 30}
1501 - 5 => {1, 30}
1501 - 6 => {1, 30}
1501 - 7 => {1, 30}
1501 - 8 => {1, 30}
1501 - 9 => {1, 30}
1501 - 10 => {1, 30}
1501 - 11 => {1, 30}
1501 - 12 => {1, 30}
1501 - 13 => {1, 5}
1502 - 1 => {1, 30}
1502 - 2 => {1, 30}
1502 - 3 => {1, 30}
1502 - 4 => {1, 30}
1502 - 5 => {1, 30}
1502 - 6 => {1, 30}
1502 - 7 => {1, 30}
1502 - 8 => {1, 30}
1502 - 9 => {1, 30}
1502 - 10 => {1, 30}
1502 - 11 => {1, 30}
1502 - 12 => {1, 30}
1502 - 13 => {1, 5}
1503 - 1 => {1, 30}
1503 - 2 => {1, 30}
1503 - 3 => {1, 30}
1503 - 4 => {1, 30}
1503 - 5 => {1, 30}
1503 - 6 => {1, 30}
1503 - 7 => {1, 30}
1503 - 8 => {1, 30}
1503 - 9 => {1, 30}
1503 - 10 => {1, 30}
1503 - 11 => {1, 30}
1503 - 12 => {1, 30}
1503 - 13 => {1, 6}
1504 - 1 => {1, 30}
1504 - 2 => {1, 30}
1504 - 3 => {1, 30}
1504 - 4 => {1, 30}
1504 - 5 => {1, 30}
1504 - 6 => {1, 30}
1504 - 7 => {1, 30}
1504 - 8 => {1, 30}
1504 - 9 => {1, 30}
1504 - 10 => {1, 30}
1504 - 11 => {1, 30}
1504 - 12 => {1, 30}
1504 - 13 => {1, 5}
1505 - 1 => {1, 30}
1505 - 2 => {1, 30}
1505 - 3 => {1, 30}
1505 - 4 => {1, 30}
1505 - 5 => {1, 30}
1505 - 6 => {1, 30}
1505 - 7 => {1, 30}
1505 - 8 => {1, 30}
1505 - 9 => {1, 30}
1505 - 10 => {1, 30}
1505 - 11 => {1, 30}
1505 - 12 => {1, 30}
1505 - 13 => {1, 5}
1506 - 1 => {1, 30}
1506 - 2 => {1, 30}
1506 - 3 => {1, 30}
1506 - 4 => {1, 30}
1506 - 5 => {1, 30}
1506 - 6 => {1, 30}
1506 - 7 => {1, 30}
1506 - 8 => {1, 30}
1506 - 9 => {1, 30}
1506 - 10 => {1, 30}
1506 - 11 => {1, 30}
1506 - 12 => {1, 30}
1506 - 13 => {1, 5}
1507 - 1 => {1, 30}
1507 - 2 => {1, 30}
1507 - 3 => {1, 30}
1507 - 4 => {1, 30}
1507 - 5 => {1, 30}
1507 - 6 => {1, 30}
1507 - 7 => {1, 30}
1507 - 8 => {1, 30}
1507 - 9 => {1, 30}
1507 - 10 => {1, 30}
1507 - 11 => {1, 30}
1507 - 12 => {1, 30}
1507 - 13 => {1, 6}
1508 - 1 => {1, 30}
1508 - 2 => {1, 30}
1508 - 3 => {1, 30}
1508 - 4 => {1, 30}
1508 - 5 => {1, 30}
1508 - 6 => {1, 30}
1508 - 7 => {1, 30}
1508 - 8 => {1, 30}
1508 - 9 => {1, 30}
1508 - 10 => {1, 30}
1508 - 11 => {1, 30}
1508 - 12 => {1, 30}
1508 - 13 => {1, 5}
1509 - 1 => {1, 30}
1509 - 2 => {1, 30}
1509 - 3 => {1, 30}
1509 - 4 => {1, 30}
1509 - 5 => {1, 30}
1509 - 6 => {1, 30}
1509 - 7 => {1, 30}
1509 - 8 => {1, 30}
1509 - 9 => {1, 30}
1509 - 10 => {1, 30}
1509 - 11 => {1, 30}
1509 - 12 => {1, 30}
1509 - 13 => {1, 5}
1510 - 1 => {1, 30}
1510 - 2 => {1, 30}
1510 - 3 => {1, 30}
1510 - 4 => {1, 30}
1510 - 5 => {1, 30}
1510 - 6 => {1, 30}
1510 - 7 => {1, 30}
1510 - 8 => {1, 30}
1510 - 9 => {1, 30}
1510 - 10 => {1, 30}
1510 - 11 => {1, 30}
1510 - 12 => {1, 30}
1510 - 13 => {1, 5}
1511 - 1 => {1, 30}
1511 - 2 => {1, 30}
1511 - 3 => {1, 30}
1511 - 4 => {1, 30}
1511 - 5 => {1, 30}
1511 - 6 => {1, 30}
1511 - 7 => {1, 30}
1511 - 8 => {1, 30}
1511 - 9 => {1, 30}
1511 - 10 => {1, 30}
1511 - 11 => {1, 30}
1511 - 12 => {1, 30}
1511 - 13 => {1, 6}
1512 - 1 => {1, 30}
1512 - 2 => {1, 30}
1512 - 3 => {1, 30}
1512 - 4 => {1, 30}
1512 - 5 => {1, 30}
1512 - 6 => {1, 30}
1512 - 7 => {1, 30}
1512 - 8 => {1, 30}
1512 - 9 => {1, 30}
1512 - 10 => {1, 30}
1512 - 11 => {1, 30}
1512 - 12 => {1, 30}
1512 - 13 => {1, 5}
1513 - 1 => {1, 30}
1513 - 2 => {1, 30}
1513 - 3 => {1, 30}
1513 - 4 => {1, 30}
1513 - 5 => {1, 30}
1513 - 6 => {1, 30}
1513 - 7 => {1, 30}
1513 - 8 => {1, 30}
1513 - 9 => {1, 30}
1513 - 10 => {1, 30}
1513 - 11 => {1, 30}
1513 - 12 => {1, 30}
1513 - 13 => {1, 5}
1514 - 1 => {1, 30}
1514 - 2 => {1, 30}
1514 - 3 => {1, 30}
1514 - 4 => {1, 30}
1514 - 5 => {1, 30}
1514 - 6 => {1, 30}
1514 - 7 => {1, 30}
1514 - 8 => {1, 30}
1514 - 9 => {1, 30}
1514 - 10 => {1, 30}
1514 - 11 => {1, 30}
1514 - 12 => {1, 30}
1514 - 13 => {1, 5}
1515 - 1 => {1, 30}
1515 - 2 => {1, 30}
1515 - 3 => {1, 30}
1515 - 4 => {1, 30}
1515 - 5 => {1, 30}
1515 - 6 => {1, 30}
1515 - 7 => {1, 30}
1515 - 8 => {1, 30}
1515 - 9 => {1, 30}
1515 - 10 => {1, 30}
1515 - 11 => {1, 30}
1515 - 12 => {1, 30}
1515 - 13 => {1, 6}
1516 - 1 => {1, 30}
1516 - 2 => {1, 30}
1516 - 3 => {1, 30}
1516 - 4 => {1, 30}
1516 - 5 => {1, 30}
1516 - 6 => {1, 30}
1516 - 7 => {1, 30}
1516 - 8 => {1, 30}
1516 - 9 => {1, 30}
1516 - 10 => {1, 30}
1516 - 11 => {1, 30}
1516 - 12 => {1, 30}
1516 - 13 => {1, 5}
1517 - 1 => {1, 30}
1517 - 2 => {1, 30}
1517 - 3 => {1, 30}
1517 - 4 => {1, 30}
1517 - 5 => {1, 30}
1517 - 6 => {1, 30}
1517 - 7 => {1, 30}
1517 - 8 => {1, 30}
1517 - 9 => {1, 30}
1517 - 10 => {1, 30}
1517 - 11 => {1, 30}
1517 - 12 => {1, 30}
1517 - 13 => {1, 5}
1518 - 1 => {1, 30}
1518 - 2 => {1, 30}
1518 - 3 => {1, 30}
1518 - 4 => {1, 30}
1518 - 5 => {1, 30}
1518 - 6 => {1, 30}
1518 - 7 => {1, 30}
1518 - 8 => {1, 30}
1518 - 9 => {1, 30}
1518 - 10 => {1, 30}
1518 - 11 => {1, 30}
1518 - 12 => {1, 30}
1518 - 13 => {1, 5}
1519 - 1 => {1, 30}
1519 - 2 => {1, 30}
1519 - 3 => {1, 30}
1519 - 4 => {1, 30}
1519 - 5 => {1, 30}
1519 - 6 => {1, 30}
1519 - 7 => {1, 30}
1519 - 8 => {1, 30}
1519 - 9 => {1, 30}
1519 - 10 => {1, 30}
1519 - 11 => {1, 30}
1519 - 12 => {1, 30}
1519 - 13 => {1, 6}
分析,我們看到,每個月有30天,除了第13個月,這(通常)有5天。看起來,每4年一次,第13個月有6天。那一定是它如何處理閏日。這肯定是一個不錯的日曆!一切都很好,很規律。
讓我們撥開周圍的一些更多:
NSRange minHourRange = [coptic minimumRangeOfUnit:NSHourCalendarUnit]; // {0,24}
NSRange maxHourRange = [coptic maximumRangeOfUnit:NSHourCalendarUnit]; // {0,24}
因此,每天有24個小時(夏令時間跳躍都不會反映在此範圍內的公曆還報告的{0,24}
最低小時範圍和最大小時。範圍爲{0,24}
,儘管有些天有23小時或25小時,取決於DST轉換)。
事情也處在分鐘和第二級(60個)正常。
所以,如果你想自己顯示日曆,你需要能夠處理在一年13個月,其中之一是不到一個星期長的UI。在分日水平,事情就是我們習慣的。
當然,您也可以閱讀科普特日曆上的Wikipedia article。
編輯(基於評論)
如果你想要做的是格式化日期爲一個字符串,那麼你會(當然)轉向NSDateFormatter
:
NSDateFormatter *f = [[NSDateFormatter alloc] init];
NSCalendar *coptic = [[NSCalendar alloc] initWithCalendarIdentifier:@"coptic"];
[f setCalendar:coptic];
[f setDateStyle:NSDateFormatterLongStyle];
NSDate *rightNow = [NSDate date];
NSString *formattedDate = [f stringFromDate:rightNow];
NSLog(@"%@", formattedDate); // logs "Bashans 4, 1728"
- 1. FullCalendar:自定義日曆
- 2. DateTimePicker自定義日曆
- 3. 自定義日曆控件
- 4. WordPress日曆自定義
- 5. Android可自定義日曆
- 6. 自定義日曆控件
- 7. Codename One - 自定義日曆日按鈕
- 8. iphone:自定義日曆提取日期
- 9. 自定義日曆和日曆適配器
- 10. 使用ios將自定義日曆添加到Google日曆?
- 11. 如何自定義日曆只顯示5天的日曆
- 12. ios自定義日曆視圖(JT日曆)
- 13. 將Google日曆與自定義日曆同步
- 14. 自定義視圖日曆中的谷歌日曆等事件
- 15. Embeding谷歌日曆的自定義日曆顏色
- 16. WPF日曆:自定義控件以顯示日曆週數
- 17. WORDPRESS:日曆與自定義帖子類型+自定義字段
- 18. Android的可自定義日曆視圖
- 19. Sharepoint 2010的自定義迷你日曆
- 20. Ionic2日曆,自定義樣式?
- 21. 谷歌日曆api - 自定義url/ico
- 22. 日曆自定義驗證器
- 23. 日曆jQuery插件:自定義視圖
- 24. 自定義日曆與引導和momentjs
- 25. 如何自定義Tapku日曆?
- 26. 使用javascript的自定義日曆
- 27. wordpress自定義查詢事件日曆
- 28. codenameone:自定義日曆按鈕背景
- 29. 全日曆自定義顏色
- 30. 自定義日曆應填充屏幕
我想科普特日期只顯示在我的視野。例如「Kiahk,29,1728」,它每天都會變化到適當的日期。 –
@DylanKatz更新了答案 –