ios - 如何仅存储没有时区和实际时间的日期

标签 ios objective-c iphone xcode

我刚刚学习 xcode,我试图在互联网上找到答案,但没有运气。
我的简单问题:如何仅存储没有时区的日期和带有核心数据的实际时间?
目前我正在使用 NSDateFormatterNSDate 存储日期:

NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
[dateFormatter setDateFormat:@"dd-MM-yyyy"];
NSDate *dateT = [dateFormatter dateFromString:self.DateLabel.text];
[ItemDate setValue: dateT forKey:@"date"];

但是如果我使用这部分代码并将存储的日期打印为日期:2015-04-17 07:00:00 +0000

基本上我只想删除这个:07:00:00 +0000并仅存储2015-04-17

可能吗?

最佳答案

Alex,获取输出日期后,您可以尝试此代码。

NSString *str1 = @"2015-04-17 07:00:00 +0000";
NSRange range = [str1 rangeOfString:@" "];

NSString *date = [str1 substringToIndex:range.location];
NSLog(@"%@",date);

关于ios - 如何仅存储没有时区和实际时间的日期,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29692458/

相关文章:

ios - transitionFromView 不工作

ios - CocoaPods 在添加新 pod 时出现问题

objective-c - 旋转 View 边缘的 CATransform3D 深度

iphone - 如何将 iAd 添加到 iPad

ios - 设置包未显示在 iPhone 设置中

iphone - NSURLConnection 委托(delegate)方法没有被调用

ios - 水平 Collection View

iOS:魔法记录的 NSPredicate 问题?

objective-c - Instruments 中的内存分配过多是否不好?

iphone - UITableViewController 拉动以使用卡住的 header 进行刷新