gpt4 book ai didi

objective-c - 来自 NSString 的 NSDate

转载 作者:太空狗 更新时间:2023-10-30 03:42:08 26 4
gpt4 key购买 nike

我已经阅读了 DateFormatting 指南,但我仍然无法获得有效的格式化程序。

NSString *string = @"0901Z 12/17/09";   
//This is a sample date. The Z stands for GMT timezone
//The 0901 is 09h 01m on a 24 hour clock not 12.
//As long as I can get the hours/min & date from the string I can deal with the time zone later
NSDateFormatter *dateFormat = [[NSDateFormatter alloc] init];
[dateFormat setDateFormat:@"hhmm'Z' MM/dd/yy"];
NSDate *date = [dateFormat dateFromString:string];

最佳答案

当我尝试时,这对我有用。添加 NSLog(@"%@", date) 到你的代码的末尾给我这个输出:

2010-02-28 12:17:22.921 app[9204:a0f] 2009-12-17 09:01:00 -0800

您遇到的问题是什么?

编辑:我想通了,你对 09:01 没有问题,但对其他 24 小时制,比如 14:25,对吧?将格式化程序更改为:

@"HHmm'Z' MM/dd/yy"

关于objective-c - 来自 NSString 的 NSDate,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2352487/

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