时间格式字符串转化为date和时间戳

    NSString *dateStr=@"2012-05-17 11:23:23";
    NSLog(@"dateStr=%@",dateStr);
    NSDateFormatter *format=[[NSDateFormatter alloc] init];
    [format setDateFormat:@"yyyy-MM-dd HH:mm:ss"];
    NSDate *fromdate=[format dateFromString:dateStr];
    NSTimeZone *fromzone = [NSTimeZone systemTimeZone];
    NSInteger frominterval = [fromzone secondsFromGMTForDate: fromdate];
    NSDate *fromDate = [fromdate  dateByAddingTimeInterval: frominterval];
    NSLog(@"fromdate=%@",fromDate);
    CGFloat timeSp = [fromDate timeIntervalSince1970];
    NSLog(@"timeSp:%f",timeSp);

posted @ 2017-06-06 12:47  yangykaifa  阅读(347)  评论(0编辑  收藏  举报