iOS 備忘錄

iOS 時區:spa

 

1 //先是將指定時區的日期轉換爲當前時區時間:   
2     NSDateFormatter *formatter = [[NSDateFormatter alloc] init];
3     [formatter setDateFormat:@"yyyy-MM-dd HH:mm:ss Z"];
4     [formatter setTimeZone:[NSTimeZone defaultTimeZone] ] ;
5     NSDate *time = [formatter dateFromString:@"2011-09-27 10:11:30 +0600"];    
6     NSLog(@"Local time is %@",[formatter stringFromDate: time]);  

 


    

1 //而後是將當前時區時間轉換爲特定時區的:
2     NSDateFormatter *formatter = [[NSDateFormatter alloc] init];
3     [formatter setDateFormat:@"yyyy-MM-dd HH:mm:ss Z"];
4     [formatter setTimeZone:[NSTimeZone timeZoneWithName:@"Asia/Tokyo"]];
5     NSLog(@"Now Tokyo time is %@",[formatter stringFromDate:[NSDate date]]);    

 


    

1 //下面是將指定時區的某個日期時間轉化爲指定時區的時間    
2     NSDateFormatter *formatter = [[NSDateFormatter alloc] init];
3     [formatter setDateFormat:@"yyyy-MM-dd HH:mm:ss Z"];
4     [formatter setTimeZone:[NSTimeZone timeZoneWithName:@"Asia/Tokyo"]];
5     NSDate *time = [formatter dateFromString:@"2011-09-27 10:11:30 +0600"];
6     NSLog(@"Tokyo time is %@",[formatter stringFromDate: time]);

 

 

1 //NSDate轉NSString:
2 NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
3 [dateFormatter setDateFormat:@"yyyy-MM-dd HH:mm:ss"];
4 NSString *strDate = [dateFormatter stringFromDate:[NSDate date]];
5 NSLog(@"%@", strDate);

 

iOS 語法糖code

NSNumber 能夠用@數字來構造,如@3或者@(3);

NSArray 能夠用@[]構造,如@[v1,v2,v3];

NSDictionary能夠用@{}構造,如@{k1:v1,k2:v2};

 

iOS版本號獲取orm

NSString *currentVersion = [[[NSBundle mainBundle] infoDictionary] objectForKey:@"CFBundleShortVersionString"];
相關文章
相關標籤/搜索