iOS 获取当前时间

乐正晟
2023-12-01

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);
 类似资料: