• ios-时间换算


    经常会遇到时间转换的,在此收藏一个时间换算的方法〜

     1 #pragma mark 时间换算
     2 
     3 + (NSString *)setcreateTime:(NSString *)str
     4 {
     5     //yyyy-MM-dd- HH:MMss"];
     6 
     7     
     8     NSDateFormatter* formatter = [[NSDateFormatter alloc] init];
     9     
    10     //[formatter setDateStyle:NSDateFormatterMediumStyle];
    11     
    12     //[formatter setTimeStyle:NSDateFormatterShortStyle];
    13     
    14     [formatter setDateFormat:@"yyyy"];
    15     
    16     [formatter setTimeZone:[NSTimeZone timeZoneWithAbbreviation:@"CCT"]];
    17     
    18     NSDate *date = [NSDate dateWithTimeIntervalSince1970:[str doubleValue]];
    19     
    20     NSString *dateStr = [formatter stringFromDate:date];
    21     
    22     //本地时间
    23     NSDate * senddate=[NSDate date];
    24     NSDateFormatter * dateformatter=[[NSDateFormatter alloc] init];
    25     [dateformatter setDateFormat:@"YYYY"];
    26     NSString * locationString=[dateformatter stringFromDate:senddate];
    27  
    28     //[dateformatter setDateFormat:@"YYYY-MM-dd-HH-mm-ss"];
    29     
    30     //判断创建时间 与 本地时间 是否同一年
    31     if ([dateStr isEqualToString:locationString]) {
    32         [formatter setDateFormat:@"MM-dd HH:mm"];
    33     }else{
    34         [formatter setDateFormat:@"yyyy-MM-dd HH:mm"];
    35     }
    36     
    37     date = [NSDate dateWithTimeIntervalSince1970:[str doubleValue]];
    38     dateStr = [formatter stringFromDate:date];
    39     
    40     return [self compareCurrentTime:date :dateStr];
    41 }
    42 
    43 + (NSString *) compareCurrentTime:(NSDate*) compareDate :(NSString *)str
    44 {
    45     NSTimeInterval  timeInterval = [compareDate timeIntervalSinceNow];
    46     timeInterval = -timeInterval;
    47     long temp = 0;
    48     NSString *result;
    49     if (timeInterval < 60) {
    50         if (timeInterval > 1) {
    51             result = [NSString stringWithFormat:@"%d秒前",(int)timeInterval+1];
    52         }else if (timeInterval < -160){
    53             result = str;
    54         }
    55         else{
    56             result = [NSString stringWithFormat:@"%d秒前",1];
    57         }
    58         
    59     }
    60     else if((temp = timeInterval/60) <60){
    61         result = [NSString stringWithFormat:@"%ld分钟前",temp];
    62     }else{
    63         result = str;
    64     }
    65     
    66 
    67     
    68     return  result;
    69 }
    View Code
  • 相关阅读:
    Windows NT 的历史
    Windows 下 Mysql8.0.12 的安装方法
    [知乎] 机械硬盘和固态硬盘的简单对比
    syncthing 多主机同步文件工具
    delphi 2007 远程调试
    关于delphi PAServer 远程调试DLL文件
    关于 datasnap Stream的英文博客能容
    DataSnap 用TStream 传递大数据 返回流大小为-1的情况
    c++ builder xe2 (Embarcadero rad studio) 远程调试 同样适用于 delphi 远程调试 教程
    Delphi10 安装Graphics32
  • 原文地址:https://www.cnblogs.com/xm5mao/p/3991202.html
Copyright © 2020-2023  润新知