首页 > 代码库 > 时间格式字符串转化为date和时间戳

时间格式字符串转化为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);

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