nsdate

MagicalRecord date parsing

若如初见. 提交于 2019-12-01 19:36:56
I've got a date in the following format: 2013-05-04T05:07:09+00:00 I'm using MagicalRecord to map the NSDate automatically. As far as I can see the above date format should comply with MagicalRecord's default date format: yyyy-MM-dd'T'HH:mm:ss'Z' . I have tried with a custom dateFormat entry in the attribute's user info (see this article ): yyyy-MM-ddTHH:mm:ss+Z , yyyy-MM-dd T HH:mm:ss Z , yyyy-MM-dd'T'HH:mm:ss'+'Z but none of them work in order to have it parse the date properly and it always returns nil regardless of setting a custom dateFormat or using MagicalRecord's default format. Let's

How to retrieve number of hours past midnight from an NSDate object?

故事扮演 提交于 2019-12-01 19:35:34
I need to retrieve the number of hours past midnight from a UIDatePicker control in an iPhone project. datePickerMode is set to UIDatePickerModeTime , so the user only can set a time, no date. When the user is done and dismisses the view the UIDatePicker is on, the following date might be retrieved (as an example): NSDate *returnTime = timePicker.date; NSLog(@"returnTime: %@", returnTime); // returns for example @"1970-01-01 10:13:00 PM +0000" As said, I'm looking for the number of hours past midnight. In the example above, that value should be 22 . I wanted to achieve this by creating an

MagicalRecord date parsing

回眸只為那壹抹淺笑 提交于 2019-12-01 18:58:35
问题 I've got a date in the following format: 2013-05-04T05:07:09+00:00 I'm using MagicalRecord to map the NSDate automatically. As far as I can see the above date format should comply with MagicalRecord's default date format: yyyy-MM-dd'T'HH:mm:ss'Z' . I have tried with a custom dateFormat entry in the attribute's user info (see this article): yyyy-MM-ddTHH:mm:ss+Z , yyyy-MM-dd T HH:mm:ss Z , yyyy-MM-dd'T'HH:mm:ss'+'Z but none of them work in order to have it parse the date properly and it always

NSSortdescriptor ineffective on fetch result from NSManagedContext

跟風遠走 提交于 2019-12-01 18:47:56
I'm trying to sort my NSFetchRequest result using a NSSortdescriptor using a key pointing to a NSDate value. My fetch results come out totally random for no clear reason. The NSManagedObjectContext I'm using is updated with a save from a nested child context created on a subclass of NSOperation. I know all this is done successfully because I can get all the data needed from the parent (main) context. Fetching from it just wont sort on date! Strange thing is; predicates for selecting the entities (called "Tweet") between two dates works just fine! Here's some code to illustrate my problem:

iOS开发之常用的那些工具类和方法

百般思念 提交于 2019-12-01 17:57:25
LBUtils: iOS开发常用工具类 NSDateUtil.h ----日期相关的工具类 功能: 指定日期格式的转换 NSFileUtil.h ----文件目录相关的工具类 功能: 获取Documents的路径 获取Cache的路径 判断文件是否存在 根据文件路径删除文件 NSString+Wrapper.h ----针对NSString的一些封装 功能: 验证字符串是否为空 获取字符串长度,区分中英文 移除字符串中的所有空字符 ...... 详细了解请前往GitHub: https://github.com/mangooc/LBUtils.git 希望对您有所帮助,欢迎开发者补充和完善,谢谢! 来源: oschina 链接: https://my.oschina.net/u/1440723/blog/657241

How to add a number of weeks to an NSDate?

自闭症网瘾萝莉.ら 提交于 2019-12-01 17:40:38
I have in the past used the below function to add on a specific time interval using NSDateComponents to an existing date. (NSDate *)dateByAddingComponents:(NSDateComponents *)comps toDate:(NSDate *)date options:(NSCalendarOptions)opts From iOS8 the week value is deprecated for NSDateComponents , which means I can't achieve what I want to do: generate a new NSDate by adding a certain number of weeks to a given NSDate . Any help would be greatly appreciated. Update: As Zaph said in his answer, Apple actually recommends using weekOfYear or weekOfMonth instead of the answer I provided. View Zaph's

How to auto generate NSManagedObject subclasses with date attribute as Date instead of NSDate?

烂漫一生 提交于 2019-12-01 17:27:08
I'm currently updating my project to Swift 3 and I'm moving all my NSDate methods and extensions to Date in order to keep the standard in the app. The problem is that I use Xcode to auto-generate my NSManagedObject subclasses and it is generating the date attributes as NSDate instead of Date. Is there a way to generate it with the date attributes as Date? EDIT Per Apple Developer Documentation : Core Data natively supports a variety of attribute types, such as string, date, and integer (represented as instances of NSString, NSDate and NSNumber respectively). So I think it's not possible =/ It

Set iPhone date/time within app for testing purposes?

删除回忆录丶 提交于 2019-12-01 16:13:51
问题 I have a lot of functionality in my app that is date/time dependent (e.g. "if date is x, show y). I use [NSDate date] to get the current date/time of the user. I can test functionality by manually changing the date/time on my iPhone but I'm wondering if there is a way to programatically overwrite the the current time so I can test in the simulator and more quickly. 回答1: You can create NSDate objects with any date/time you want. Just run your code through a method to get "the current" time and

Number of weeks in month

拈花ヽ惹草 提交于 2019-12-01 15:11:07
I have the following code: NSDate *dateNow = [[NSDate alloc] init]; NSTimeInterval timeDifference = [usersDate timeIntervalSinceDate:dateNow]; // Get the system calendar NSCalendar *sysCalendar = [NSCalendar currentCalendar]; // Create the NSDates NSDate *date1 = [[NSDate alloc] init]; NSDate *date2 = [[NSDate alloc] initWithTimeInterval:timeDifference sinceDate:date1]; // Get conversion to months, days, hours, minutes unsigned int unitFlags = NSWeekCalendarUnit | NSYearCalendarUnit | NSMonthCalendarUnit | NSSecondCalendarUnit | NSHourCalendarUnit | NSMinuteCalendarUnit | NSDayCalendarUnit |

Is there a way to convert a natural language date NSString to an NSDate

主宰稳场 提交于 2019-12-01 15:09:49
问题 Say I have the NSString @"tomorrow" Is there any library that takes strings such as this and converts them into NSDates? I'm imagining/hoping for something like this: NSString* humanDate = @"tomorrow at 4:15"; NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init]; [dateFormatter setDateFormat:@"x at HH:MM"]; NSDate* date = [dateFormatter dateFromString:humanDate]; I would also want to do things like "Next monday", etc. but it doesn't have to be super sophisticated. I can enforce