1970年时间转换

+ ( NSString *)startTime:( NSString *)startTime endTime:( NSString
*)endTime{
   
NSString *startTimeStr = [[ NSString alloc] init
];
   
NSString *endTimeStr = [[ NSString alloc] init
];
   
NSInteger startDay = 0
;
   
NSInteger endDay = 0
;
   
if
(startTime) {
       
NSDate *date = [ NSDate dateWithTimeIntervalSince1970:[startTime integerValue] / 1000
];
       
NSInteger month = [ Utility timeWithDate:date timeType: TimeTypeMouth
];
        startDay  = [
Utility timeWithDate:date timeType: TimeTypeDay
];
       
NSInteger hour = [ Utility timeWithDate:date timeType: TimeTypeHour
];
       
NSInteger minute = [ Utility timeWithDate:date timeType: TimeTypeMinute
];
        startTimeStr = [
NSString stringWithFormat: @"%02ld %02ld %02ld:%02ld"
,month,startDay,hour,minute];
    }
   
if
(endTime) {
       
NSDate *date = [ NSDate dateWithTimeIntervalSince1970:[startTime integerValue] / 1000
];
       
NSInteger month = [ Utility timeWithDate:date timeType: TimeTypeMouth
];
        endDay  = [
Utility timeWithDate:date timeType: TimeTypeDay
];
       
NSInteger hour = [ Utility timeWithDate:date timeType: TimeTypeHour
];
       
NSInteger minute = [ Utility timeWithDate:date timeType: TimeTypeMinute
];
       
if
(startDay == endDay) {
            endTimeStr = [
NSString stringWithFormat: @"%02ld:%02ld"
,hour,minute];
        }
else
{
            endTimeStr = [
NSString stringWithFormat: @"%02ld %02ld %02ld:%02ld"
,month,endDay,hour,minute];
        }
    }
   
NSString *dataTimeStr = [ NSString stringWithFormat: @"%@-%@"
,startTimeStr,endTimeStr];
   
return
dataTimeStr;
}

+ (
NSString *)createTime:( NSString
*)time{
   
NSDate *date = [ NSDate dateWithTimeIntervalSince1970:[time integerValue] / 1000
];
   
NSInteger year = [ Utility timeWithDate:date timeType: TimeTypeYear
];
   
NSInteger month = [ Utility timeWithDate:date timeType: TimeTypeMouth
];
   
NSInteger day  = [ Utility timeWithDate:date timeType: TimeTypeDay
];
   
NSInteger hour = [ Utility timeWithDate:date timeType: TimeTypeHour
];
   
NSInteger minute = [ Utility timeWithDate:date timeType: TimeTypeMinute
];
   
NSInteger second = [ Utility timeWithDate:date timeType: TimeTypeSecond
];
   
NSString *dateStr = [ NSString stringWithFormat: @"%ld-%02ld-%02ld %02ld:%02ld:%02ld"
,year,month,day,hour,minute,second];
   
return
dateStr;
}

+ (
NSInteger)timeWithDate:( NSDate *)date timeType:( TimeType
)timeType {
   
NSCalendar *calendar = [ NSCalendar currentCalendar
];
   
NSDateComponents *compt = [calendar components:( NSYearCalendarUnit| NSMonthCalendarUnit| NSDayCalendarUnit| NSHourCalendarUnit| NSMinuteCalendarUnit| NSSecondCalendarUnit) fromDate
:date];
   
NSInteger year = [compt year
];
   
NSInteger month = [compt month
];
   
NSInteger day = [compt day
];
   
NSInteger hour = [compt hour
];
   
NSInteger minute = [compt minute
];
   
NSInteger second = [compt second
];
   
switch
(timeType) {
       
case TimeTypeYear
:
           
return
year;
           
break
;
       
case TimeTypeMouth
:
           
return
month;
           
break
;
       
case TimeTypeDay
:
           
return
day;
           
break
;
       
case TimeTypeHour
:
           
return
hour;
           
break
;
       
case TimeTypeMinute
:
           
return
minute;
           
break
;
       
case TimeTypeSecond
:
           
return
second;
           
break
;
           
       
default: return 1
;
           
break
;
    }
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值