1.iOS NSTimeZone 自定义时区的使用(收集):
http://www.jianshu.com/p/9c882fc4bc73
2.iOS时间与日期处理(收集):
http://www.jianshu.com/p/418035e65877
3.时间转换
[NSTimeZone systemTimeZone];//系统所在时区
[NSTimeZone defaultTimeZone];//默认时区,貌似和上一个没什么区别
[NSTimeZone timeZoneForSecondsFromGMT:0];//这就是GMT+0时区了
- (NSString *)timeFormate:(NSTimeInterval)time
{
int sec = time;
NSDate *date = [NSDate dateWithTimeIntervalSince1970:sec];
NSDateFormatter *formatter = [[NSDateFormatter alloc] init];
NSTimeZone* GTMzone = [NSTimeZone timeZoneForSecondsFromGMT:8];
[formatter setTimeZone:GTMzone];
NSString *timeStr = nil;
if (sec < 60)
{
if (sec < 10)
{
timeStr = [NSString stringWithFormat:@"0%d",sec];
}
else
{
timeStr = [NSString stringWithFormat:@"%d",sec];
}
timeStr = [NSString stringWithFormat:@"00:00:%@",timeStr];
}
else if (sec < 3600)
{
[formatter setDateFormat:@"mm:ss"];
timeStr = [formatter stringFromDate:date];
timeStr = [NSString stringWithFormat:@"00:%@",timeStr];
}
else
{
[formatter setDateFormat:@"HH:mm:ss"];
timeStr = [formatter stringFromDate:date];
}
return timeStr;
}