nsdate

Number of day of current year in iOS

独自空忆成欢 提交于 2019-12-01 12:31:10
问题 I want to find number of day today is in current year. e.g, if today is Mar15, 2012 I should get 75(31 + 29 + 15). Or we can simply say that number of days between today and Jan01 of current year. 回答1: Use the ordinalityOfUnit method of the NSCalendar to get the day number in the year - specify the NSDayCalendarUnit inUnit:NSYearCalendarUnit NSCalendar *currentCalendar = [NSCalendar currentCalendar]; NSDate *today = [NSDate date]; NSInteger dc = [currentCalendar ordinalityOfUnit

Comparing dates in Cocoa

泪湿孤枕 提交于 2019-12-01 12:23:45
hi i want to know how to get current date? i want to compare current date with a date i m fetching from a plist files using following code. NSDate *expDate = [licenseDictionary objectForKey:@"Expires"]; for comparison i m using the following code if([curDate compare:expDate] == NSOrderedAscending ) but its not working. can anybody help me. In the interest of teaching someone how to fish rather than just feeding him: Have a look at the Date and Time Programming Guide. . The Programming Guides in the documentation are your first stop when trying to understand a topic. They provide an overview of

Swift How to convert Parse createdAt time to time ago?

て烟熏妆下的殇ゞ 提交于 2019-12-01 12:20:16
I've retrieved createdAt column from Parse and i wrote it on UITableview for each row, but the time and date looks like this on tableview : 23-12-2015 01:04:56.380 28-08-2015 19:45:09.101 I want to convert that to time ago for example: Today 1:04 PM -- Yestarday 5:24 AM -- 3 days ago -- 1 week ago -- 1 month ago Here is my code: let dateFormatter = NSDateFormatter() dateFormatter.dateFormat = "dd-MM-yyyy HH:mm:ss.SSS" let date = dateFormatter.stringFromDate((msg.createdAt as NSDate?)!) Cell.timelbl.text = date I'm using xcode 7 beta Any help please? You can use NSCalendar isDateInToday to

iOS: How to measure passed time, independent of clock and time zone changes?

不羁的心 提交于 2019-12-01 12:17:38
问题 In order to measure the time duration while my app is running, as well as the time that passed while my app was idle in the background, I need a reference clock that is not altered by the user changing the Time+Date of his calendar clock. I can not rely on NSDate because that can be changed by the user while my app is in the background (and no, intercepting the notifications related to such clock changes is overkill for my needs). What I need is a function such as " seconds since boot of the

Number of weeks in month

拜拜、爱过 提交于 2019-12-01 12:14:39
问题 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 |

iOS: How to measure passed time, independent of clock and time zone changes?

戏子无情 提交于 2019-12-01 12:09:16
In order to measure the time duration while my app is running, as well as the time that passed while my app was idle in the background, I need a reference clock that is not altered by the user changing the Time+Date of his calendar clock. I can not rely on NSDate because that can be changed by the user while my app is in the background (and no, intercepting the notifications related to such clock changes is overkill for my needs). What I need is a function such as " seconds since boot of the OS". Mac OS offer such functions (both Ticks and Microseconds ), but what about iOS? #include <mach

Swift How to convert Parse createdAt time to time ago?

白昼怎懂夜的黑 提交于 2019-12-01 11:58:59
问题 I've retrieved createdAt column from Parse and i wrote it on UITableview for each row, but the time and date looks like this on tableview : 23-12-2015 01:04:56.380 28-08-2015 19:45:09.101 I want to convert that to time ago for example: Today 1:04 PM -- Yestarday 5:24 AM -- 3 days ago -- 1 week ago -- 1 month ago Here is my code: let dateFormatter = NSDateFormatter() dateFormatter.dateFormat = "dd-MM-yyyy HH:mm:ss.SSS" let date = dateFormatter.stringFromDate((msg.createdAt as NSDate?)!) Cell

iPhone: How to convert “yyyyMMddThhmmss” format string to NSDate?

我怕爱的太早我们不能终老 提交于 2019-12-01 11:54:57
I have a string like " 20121124T103000 " and I want to convert this to NSDate . I tried converting it with dateFormatter date format " yyyyMMddThhmmss " but it gives output as 2001-01-01 00:00:00 +0000 which is incorrect. What is the way we can convert this string to NSDate ? Here is my code: NSDateFormatter *dateFormat = [[NSDateFormatter alloc] init]; [dateFormat setDateFormat:@"yyyyMMddThhmmss"]; NSLog(@"%@",[dateFormat dateFromString:@"20121124T103000"]); Any help is appreciated. do like this, NSString *dateStr = @"20121124T103000"; NSDateFormatter *dateFormat = [[NSDateFormatter alloc]

Fire UILocalNotification in a specific Date

不打扰是莪最后的温柔 提交于 2019-12-01 11:44:03
问题 I want to fire a UILocalNotification in a specific Date. If I use this code: NSCalendar *gregorian = [[NSCalendar alloc] initWithCalendarIdentifier:NSGregorianCalendar]; NSDateComponents *components = [gregorian components:NSYearCalendarUnit | NSMonthCalendarUnit | NSDayCalendarUnit fromDate:[NSDate date]]; [components setHour:4]; [components setMinute:0]; NSDate *fireDate = [gregorian dateFromComponents:components]; If now it's 3 pm this works fine, but it doesn't when, for example, it's 5

iPhone: How to convert “yyyyMMddThhmmss” format string to NSDate?

余生长醉 提交于 2019-12-01 11:33:51
问题 I have a string like " 20121124T103000 " and I want to convert this to NSDate . I tried converting it with dateFormatter date format " yyyyMMddThhmmss " but it gives output as 2001-01-01 00:00:00 +0000 which is incorrect. What is the way we can convert this string to NSDate ? Here is my code: NSDateFormatter *dateFormat = [[NSDateFormatter alloc] init]; [dateFormat setDateFormat:@"yyyyMMddThhmmss"]; NSLog(@"%@",[dateFormat dateFromString:@"20121124T103000"]); Any help is appreciated. 回答1: do