iOS 获取当前时间

iOS获取当前时间制定格式的字符串。

 NSDateFormatter *formatter = [[NSDateFormatter alloc] init];
        NSTimeZone* timeZone = [NSTimeZone timeZoneWithName:@"Asia/Shanghai"];
        [formatter setTimeZone:timeZone];
        [formatter setDateFormat:@"yyyy-MM-dd HH:mm:ss"];
        NSString *timeString = [formatter stringFromDate:[NSDate date]];
        NSLog(@"The time is %@", timeString);

你可能感兴趣的:(iOS)