gpt4 book ai didi

ios - IOS 中的日期时间/字符串格式

转载 作者:可可西里 更新时间:2023-11-01 05:01:24 30 4
gpt4 key购买 nike

我有一个 NSString,它是这段代码中的日期和时间:“YYYY-MM-DD HH:mm:SS”,我想像德国风格一样使用它:“DD.MM.YYY HH:mm:DD "

如何解决?

最佳答案

将一个日期字符串转换为另一种格式的示例:

NSString *currentDateString = @"04-08-2012 08:16:00";

NSLog(@"currentDateString: %@", currentDateString);

NSDateFormatter *dateFormater = [[NSDateFormatter alloc] init];

[dateFormater setDateFormat:@"MM-DD-yyyy HH:mm:ss"];
NSDate *currentDate = [dateFormater dateFromString:currentDateString];
NSLog(@"currentDate: %@", currentDate);

[dateFormater setDateFormat:@"yyyy-MM-DD HH:mm:ss"];
NSString *convertedDateString = [dateFormater stringFromDate:currentDate];
NSLog(@"convertedDateString: %@", convertedDateString);

[dateFormater setDateFormat:@"DD.MM.yyy HH:mm:DD"];
NSString *germanDateString = [dateFormater stringFromDate:currentDate];
NSLog(@"germanDateString: %@", germanDateString);

NSLog输出:
当前日期字符串:04-08-2012 08:16:00
当前日期:2012-04-01 12:16:00 +0000
convertedDateString: 2012-04-92 08:16:00
germanDateString: 92.04.2012 08:16:92

关于ios - IOS 中的日期时间/字符串格式,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10062090/

30 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com