NSDate


//    NSData *nowDate =  [[NSDate alloc]init];
    NSDate *nowDate2 = [NSDate date];
    NSLog(@"%@",nowDate2);

    //1970年到当前时间的时间戳
    NSTimeInterval time1970 = [nowDate2 timeIntervalSince1970];
    NSLog(@"%lf",time1970);


  //若是代码测试过,日期时间和你的不同,你要设置时区(北京)
  
   //获取全部时区的名字
    NSArray *arr = [NSTimeZone knownTimeZoneNames];
    NSTimeZone *timeZone = [NSTimeZone timeZoneWithName:@"GMT"];
    NSLog(@"%@",arr);
    
    NSDate *nowDate = [NSDate date];
    NSDateFormatter *dateFormatter = [[NSDateFormatter alloc]init];
    [dateFormatter setDateFormat:@"YYYY-MM-DD HH-mm-ss"];//设置格式化 日期格式  zz表明时区
    [dateFormatter setTimeZone:timeZone];//设置格式化时区
    NSString *timeformatter = [dateFormatter stringFromDate:nowDate];
    NSLog(@"%@",timeformatter);
    
    
    NSString *str = @"2014年06月21日 19点25分04秒";
    NSDateFormatter *timeFormatter = [[NSDateFormatter alloc]init];
    [timeFormatter setDateFormat:@"YYYY年MM月DD日 HH点mm分ss秒"];
    NSData *date = [timeFormatter dateFromString:str];
    
    NSLog(@"%@",date);
相关文章
相关标签/搜索