gpt4 book ai didi

iphone - 我在这个日期格式化程序中做错了什么

转载 作者:行者123 更新时间:2023-11-28 19:19:41 24 4
gpt4 key购买 nike

 NSDate *date=[[NSDate alloc] init];
NSDateFormatter *dfLocal=[[NSDateFormatter alloc]init];
[dfLocal setDateFormat:@"yyyy-MM-dd"];
date=[dfLocal dateFromString:@"2011-09-22"];
NSLog(@"the date is %@",date);

这是我的代码,输出为..

2012-04-02 18:13:45.338 TimeProblem[2656:207] the date is 2011-09-21 18:30:00 +0000

为什么要将这个.. 18:30:00 +0000 追加到最后..?我只希望它是 00:00:00 +0000

最佳答案

在下面使用:

NSDate *date=[[NSDate alloc] init];
NSDateFormatter *dfLocal=[[NSDateFormatter alloc]init];
[dfLocal setDateFormat:@"yyyy-MM-dd"];
[dfLocal setTimeZone:[NSTimeZone timeZoneWithAbbreviation:@"GMT"]];
date=[dfLocal dateFromString:@"2011-09-22"];

NSLog(@"the date is %@",date);

关于iphone - 我在这个日期格式化程序中做错了什么,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9976726/

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