美文网首页
NSDate转时间

NSDate转时间

作者: 邹邹_ZZ | 来源:发表于2016-09-07 17:32 被阅读26次

    NSDate转时间

    + (NSString *)dateStringFromDate:(NSDate *)date formate:(NSString *)formate;{
        NSDateFormatter *formatter = [[NSDateFormatter alloc] init];
        [formatter setDateFormat:formate];
        NSString *dateString = [formatter stringFromDate:date];
        return dateString;
    }
    

    时间转成NSDate

    + (NSDate *)dateFormDateString:(NSString *)dateString formate:(NSString *)formate{
        NSDateFormatter *fotmatter = [[NSDateFormatter alloc] init];
        [fotmatter setDateFormat:formate];
        NSDate *date = [fotmatter dateFromString:dateString];
        return date;
    }
    
    + (double)timeForDate:(NSDate *)date
    {
        double time = [date timeIntervalSince1970];
        return time;
    }
    + (NSString *)datefromTime:(long)tiem
    {
        NSDate *date = [NSDate dateWithTimeIntervalSince1970:tiem];
       return [HHTool dateStringFromDate:date formate:@"yyyyMMdd"];
    }
    

    时间转时间戳

    + (double)timeForDateString:(NSString *)dateString
    {
        NSDateFormatter *formatter = [[NSDateFormatter alloc] init];
        [formatter setDateFormat:@"yyyyMMdd"];
        NSDate *date = [formatter dateFromString:dateString];
        return [HHTool timeForDate:date];
    }
    

    美国时间转成中国时间 //Sat Jan 12 11:50:16 +0800 2013

    + (NSString *)formateString:(NSString *)dateString
    {
        NSString *formate = @"E MMM d HH:mm:ss Z yyyy";
        NSDate *date = [HHTool dateFormDateString:dateString formate:formate];
        NSString *dateStr = [HHTool dateStringFromDate:date formate:@"MM-dd:HH:mm"];
        return dateStr;
    }
    

    相关文章

      网友评论

          本文标题:NSDate转时间

          本文链接:https://www.haomeiwen.com/subject/yqnjettx.html