nsdate

Current Week Start and End Date

我与影子孤独终老i 提交于 2019-12-28 01:55:12
问题 I want to get the current week start and end date and I also want to use the previous week start and end date and next week of the start and end date in current month. Thanks in Advance. 回答1: rangeOfUnit:startDate:interval:forDate:. It gives you the start and the interval for a certain time unit. With it it is easy to find the start of the week in the used calendar and add the range-1 to get the latest second in that week. NSCalendar *cal = [NSCalendar currentCalendar]; NSDate *now = [NSDate

c++学习总结:获取13位系统时间戳

大憨熊 提交于 2019-12-27 21:19:12
【推荐】2019 Java 开发者跳槽指南.pdf(吐血整理) >>> 在iOS中使用NSDate来处理时间相关的操作,这在iOS客户端开发中非常方便。如果中间层使用c++来写的话,为了保证中间层代码的纯净,不能在c++中混编OC代码,这时候就要使用c++的方法来产生13位时间戳,向外传递给OC调用,如下代码展示了如何生成13位时间戳的方式, #if defined(__APPLE__) #define sprintf_s snprintf #endif time_t t = time(NULL); char timeInterval[32] = {0}; sprintf_s(timeInterval, sizeof(timeInterval), "%ld000", t); //timeInterval即为13位的时间戳。 这时候timeInterval即为c++中间层传递给OC的13位时间戳,将其转换成OC时间的方法乳腺下所示, //将中间层传过来的c++时间戳strtime转换成iOS中的时间 NSDateFormatter *formatter =[[NSDateFormatter alloc] init]; [formatter setDateFormat:@"MM/dd HH:mm"]; //atol()将const char*字符串转换为长整形long NSDate

How to convert NSDate in to relative format as “Today”,“Yesterday”,“a week ago”,“a month ago”,“a year ago”?

馋奶兔 提交于 2019-12-27 19:09:22
问题 I want to convert nsdate in to relative format like "Today","Yesterday","a week ago","a month ago","a year ago","date as it is" . I have written following method for it.. but some how its just printing as it is date.. can you please tell me what should be the problem? //Following is my function which converts the date into relative string +(NSString *)getDateDiffrence:(NSDate *)strDate{ NSDateFormatter *df = [[NSDateFormatter alloc] init]; df.timeStyle = NSDateFormatterMediumStyle; df

Number of days between two NSDates [duplicate]

一世执手 提交于 2019-12-27 09:00:10
问题 This question already has answers here : Objective C - calculating the number of days between two dates (6 answers) Closed 4 years ago . How could I determine the number of days between two NSDate values (taking into consideration time as well)? The NSDate values are in whatever form [NSDate date] takes. Specifically, when a user enters the inactive state in my iPhone app, I store the following value: exitDate = [NSDate date]; And when they open the app back up, I get the current time: NSDate

Why is my timer counting down by 3 every second?

一个人想着一个人 提交于 2019-12-26 15:22:45
问题 I have a timer that's counting down by 3. I'm triggering the timer in the viewDidLoad method where I'm also querying time variables from Parse. Here's my code where the timer function is: var createdAt = object.createdAt if createdAt != nil { let calendar = NSCalendar.currentCalendar() let comps = calendar.components([.Hour, .Minute, .Second], fromDate: createdAt as NSDate!) let hour = comps.hour * 3600 let minute = comps.minute * 60 let seconds = comps.second self.timerInt.append(hour +

How can I create an array of certain times?

眉间皱痕 提交于 2019-12-25 20:38:13
问题 I want to create an array of times and than sort through them to find when the next closest time in the array is (if it passes a time, then it will choose the next one as next closest). How can I do this? I don't want it to specify year, month, or day. I just want to filter through the time of day (hours, minutes, seconds). I would like to get how many seconds until the next time in the NSArray . I have looked at NSDate and noticed there is a timeIntervalSinceDate method but I do not know how

Sorting NSArray of Dictionary containing Date as String

我是研究僧i 提交于 2019-12-25 17:24:48
问题 I want to sort the following array based on the Date parameter but the problem is from a server I am not getting a timestamp , I am getting the date as a string , can anyone please help. NSArray *array = @[ @{@"valid":@"Y",@"mof":@"ON",@"dof":@"17-05-2019",@"rtntype":@"CODE1",@"ret_prd":@"042019"}, @{@"valid":@"Y",@"mof":@"ON",@"dof":@"19-04-2019",@"rtntype":@"CODE1",@"ret_prd":@"032019"}, @{@"valid":@"Y",@"mof":@"ON",@"dof":@"19-04-2019",@"rtntype":@"CODE2",@"ret_prd":@"032019"} ]; I have

How to convert a date string like “2011-06-25T11:00:26+01:00” to a long like iphone?

僤鯓⒐⒋嵵緔 提交于 2019-12-25 17:04:52
问题 I need to convert this string date "2011-06-25T11:00:26+01:00” into a long like value. I tried this NSDateFormatter *df = [[[NSDateFormatter alloc] init] autorelease]; [df setTimeZone:[NSTimeZone timeZoneWithName:@"UTC"]]; [df setDateFormat:@"yyyy-MM-ddHH:mm:ssZ"]; NSDate *date = [df dateFromString:[time stringByReplacingOccurrencesOfString:@"T" withString:@""]]; [df setDateFormat:@"eee MMM dd, yyyy hh:mm"]; NSLog(@"time%@", time); long lgTime = (long)[date timeIntervalSince1970]; but this

Getting wrong time difference

荒凉一梦 提交于 2019-12-25 16:58:30
问题 I not understand where i'm wrong to getting correct difference of two dates, -(void)updateTimeLabel{ NSString *serverResponseTimeString = @"02-08-2014 05:26:32"; NSString *systemDateString = @"02-08-2014 05:31:46"; NSDate *serverTime = [self dateFromWebStringResponse:serverResponseTimeString]; NSDate *systemDate = [self dateFromWebStringResponse:systemDateString]; NSLog(@"serverResponseTime %@", serverResponseTimeString); NSLog(@"serverTime %@", serverTime); NSLog(@"systemDate %@", systemDate

date in a specific range with NSOrderedAscending and NSOrderedDescending

人走茶凉 提交于 2019-12-25 16:24:54
问题 I have this code: NSComparisonResult compareStart = [firstDate compare: dateSelected]; NSComparisonResult compareEnd = [secondDate compare: dateSelected]; if (((compareStart == NSOrderedAscending) || (compareStart == NSOrderedSame)) && (compareEnd == NSOrderedDescending)) but it don't entry in the "if" when firstDate = dateSelected or secondDate = dateSelected...why?? 回答1: Are you sure that when firstDate equals dateSelected that date selected is earlier than secondDate? Currently your logic