/*
G:? ? ? ? 公元時(shí)代,例如AD公元
yy:? ? 年的后2位
yyyy:? ? 完整年
MM:? ? 月,顯示為1-12,帶前置0
MMM:? ? 月,顯示為英文月份簡(jiǎn)寫,如 Jan
MMMM:? ? 月,顯示為英文月份全稱,如 Janualy
dd:? ? 日,2位數(shù)表示,如02
d:? ? ? ? 日,1-2位顯示,如2,無(wú)前置0
EEE:? ? 簡(jiǎn)寫星期幾,如Sun
EEEE:? ? 全寫星期幾,如Sunday
aa:? ? 上下午,AM/PM
H:? ? ? ? 時(shí),24小時(shí)制,0-23
HH:? ? 時(shí),24小時(shí)制,帶前置0
h:? ? ? ? 時(shí),12小時(shí)制,無(wú)前置0
hh:? ? 時(shí),12小時(shí)制,帶前置0
m:? ? ? ? 分,1-2位
mm:? ? 分,2位,帶前置0
s:? ? ? ? 秒,1-2位
ss:? ? 秒,2位,帶前置0
S:? ? ? ? 毫秒
Z:? ? ? ? GMT(時(shí)區(qū))
//任何NSTimeZone對(duì)象所代表的時(shí)區(qū)都是相對(duì)于GMT的, iOS中的時(shí)間類NSDate所獲取到的時(shí)間, 都是相對(duì)于GMT的.
1、NSTimeZone 時(shí)區(qū)的創(chuàng)建
NSTimeZone *zone1 = [[NSTimeZone alloc] init];
// 根據(jù)時(shí)區(qū)名稱創(chuàng)建
NSTimeZone *zone2 = [[NSTimeZone alloc] initWithName:@"America/Chicago"];
NSTimeZone *zone3 = [NSTimeZone timeZoneWithName:@"America/Chicago"];
// 根據(jù)時(shí)區(qū)縮寫創(chuàng)建
NSTimeZone *zone4 = [NSTimeZone timeZoneWithAbbreviation:@"EST"];
// 根據(jù)零時(shí)區(qū)的秒數(shù)偏移量創(chuàng)建
NSTimeZone *zone5 = [NSTimeZone timeZoneForSecondsFromGMT:28800];
2、NSTimeZone 時(shí)區(qū)的設(shè)置
// 設(shè)置默認(rèn)的時(shí)區(qū)
[NSTimeZone setDefaultTimeZone:[[NSTimeZone alloc] initWithName:@"America/Chicago"]];
NSTimeZone *systemZone = [NSTimeZone systemTimeZone];
// 本地時(shí)區(qū)可以被修改,而系統(tǒng)時(shí)區(qū)不能修改。
NSTimeZone *localZone = [NSTimeZone localTimeZone];
NSTimeZone *defaultZone = [NSTimeZone defaultTimeZone];
// NSCalendar 設(shè)置時(shí)區(qū)
//設(shè)置時(shí)區(qū),設(shè)置為 GMT+8,即北京時(shí)間(+8)
NSCalendar *calendar = [NSCalendar currentCalendar];
[calendar setTimeZone:[NSTimeZone timeZoneWithAbbreviation:@"CET"]];
[calendar setTimeZone:[NSTimeZone timeZoneForSecondsFromGMT:+28800]];
// NSDateFormatter 設(shè)置時(shí)區(qū)
NSDateFormatter *formatter = [[NSDateFormatter alloc] init];
// 設(shè)置時(shí)區(qū),設(shè)置為 GMT
[formatter setTimeZone:[NSTimeZone timeZoneForSecondsFromGMT:0]];
3、NSTimeZone 時(shí)區(qū)的獲取
// 獲取系統(tǒng)時(shí)區(qū)
NSTimeZone *zone1 = [NSTimeZone systemTimeZone];
// 獲取本地時(shí)區(qū)
NSTimeZone *zone2 = [NSTimeZone localTimeZone];
// 獲取默認(rèn)時(shí)區(qū)
NSTimeZone *zone3 = [NSTimeZone defaultTimeZone];
4、獲取時(shí)區(qū)的名稱
// 獲取所有已知的時(shí)區(qū)名稱
NSArray *zoneNames = [NSTimeZone knownTimeZoneNames];
NSTimeZone *zone = [NSTimeZone localTimeZone];
// 獲取指定時(shí)區(qū)的名稱
NSString *strZoneName = [zone name];
5、獲取時(shí)區(qū)的縮寫
// 獲取所有已知的時(shí)區(qū)縮寫
NSDictionary *zoneAbbreviations = [NSTimeZone abbreviationDictionary];
NSTimeZone *zone = [NSTimeZone localTimeZone];
// 獲取指定時(shí)區(qū)的縮寫
NSString *zoneAbbreviation1 = [zone abbreviation];
// 獲取指定時(shí)間所在時(shí)區(qū)名稱縮寫
NSString *zoneAbbreviation2 = [zone abbreviationForDate:[NSDate date]];
6、獲取與零時(shí)區(qū)的間隔秒數(shù)
NSTimeZone *zone = [NSTimeZone localTimeZone];
// 獲取當(dāng)前時(shí)區(qū)與零時(shí)區(qū)的間隔秒數(shù)
NSInteger seconds1 = [zone secondsFromGMT];
// 獲取指定時(shí)間所在時(shí)區(qū)與零時(shí)區(qū)的間隔秒數(shù)
NSInteger seconds2 = [zone secondsFromGMTForDate:[NSDate date]];
7、時(shí)區(qū)差值轉(zhuǎn)換
// 得到當(dāng)前時(shí)間(世界標(biāo)準(zhǔn)時(shí)間 UTC/GMT)
NSDate *date = [NSDate date];
// 設(shè)置系統(tǒng)時(shí)區(qū)為本地時(shí)區(qū)
NSTimeZone *zone = [NSTimeZone systemTimeZone];
// 計(jì)算本地時(shí)區(qū)與 GMT 時(shí)區(qū)的時(shí)間差
NSInteger interval = [zone secondsFromGMT];
// 在 GMT 時(shí)間基礎(chǔ)上追加時(shí)間差值,得到本地時(shí)間
date = [date dateByAddingTimeInterval:interval];
*/