zoukankan      html  css  js  c++  java
  • OC ----关于时间的处理

     

    //获得当前时间距1970的秒数

    - (NSString *)setCurrTimeLenght

    {

        NSTimeInterval time = [[NSDate date] timeIntervalSince1970];

        NSString *timeLenght = [NSString stringWithFormat:@"%0.0f",time];

        return timeLenght;

    }

     

    //根据距离1970年的秒数算给定秒数的日期时间

    - (NSString *)getTimeString

    {

        NSString *strTime = [[NSString alloc]initWithString:self];

        

        NSDate *mydate1970 = [NSDate dateWithTimeIntervalSince1970: strTime.length >

    ([self setCurrTimeLenght].length+2)

     ? ([strTime longLongValue]/1000) : [strTime longLongValue]];

        NSDateFormatter *dateFormatter = [[NSDateFormatter alloc]init];

        [dateFormatter setDateFormat:@"yyyy-MM-dd HH:mm:ss"];  //时间格式

        

        dateFormatter.locale = [NSLocale localeWithLocaleIdentifier:@"zh_CN"];

        strTime = [dateFormatter stringFromDate:mydate1970];

        

        return strTime;

    }

     

    //获取只有时分秒

    - (NSString *)getHoursMinutesString

    {

        NSString *strTime = [[NSString alloc]initWithString:self];

        NSDate *mydate1970 = [NSDate dateWithTimeIntervalSince1970: strTime.length > ([self setCurrTimeLenght].length+2) ? ([strTime longLongValue]/1000) : [strTime longLongValue]];

        NSDateFormatter *dateFormatter = [[NSDateFormatter alloc]init];//@"yyyy-MM-dd HH:mm:ss"

        [dateFormatter setDateFormat:@"HH:mm:ss"];

        

        dateFormatter.locale = [NSLocale localeWithLocaleIdentifier:@"zh_CN"];

        strTime = [dateFormatter stringFromDate:mydate1970];

        

        

        return strTime;

    }

     

     

    //获取时分

    - (NSString *)getHoursMinString

    {

        NSString *strTime = [[NSString alloc]initWithString:self];

        NSDate *mydate1970 = [NSDate dateWithTimeIntervalSince1970: strTime.length > ([self setCurrTimeLenght].length+2) ? ([strTime longLongValue]/1000) : [strTime longLongValue]];

        NSDateFormatter *dateFormatter = [[NSDateFormatter alloc]init];

        [dateFormatter setDateFormat:@"HH:mm"];

        

        dateFormatter.locale = [NSLocale localeWithLocaleIdentifier:@"zh_CN"];

        strTime = [dateFormatter stringFromDate:mydate1970];

        

        return strTime;

     

    }

  • 相关阅读:
    协方差的意义
    ios7新特性实践
    微信支付大盗--黑色产业链
    UVA 297 Quadtrees(四叉树建树、合并与遍历)
    HDU 2876 Ellipse, again and again
    java中接口的定义与实现
    Oracle Linux 6.3下安装Oracle 11g R2(11.2.0.3)
    Fortran使用隐形DO循环和reshape给一维和多维数组赋初值
    Java实现 蓝桥杯VIP 算法训练 成绩的等级输出
    Java实现 蓝桥杯VIP 算法训练 成绩的等级输出
  • 原文地址:https://www.cnblogs.com/qwer-BHS/p/5316143.html
Copyright © 2011-2022 走看看