nsdate

Formatting NSDate into particular styles for both year, month, day, and hour, minute, seconds

寵の児 提交于 2019-12-17 02:26:26
问题 I basically need to get current date and time separately, formatted as: 2009-04-26 11:06:54 The code below, from another question on the same topic, generates now: |2009-06-01 23:18:23 +0100| dateString: |Jun 01, 2009 23:18| parsed: |2009-06-01 23:18:00 +0100| This is almost what I'm looking for, but I want to separate the day and time. NSDateFormatter *format = [[NSDateFormatter alloc] init]; [format setDateFormat:@"MMM dd, yyyy HH:mm"]; NSDate *now = [[NSDate alloc] init]; NSString

Difference between 'YYYY' and 'yyyy' in NSDateFormatter

北城余情 提交于 2019-12-16 22:13:09
问题 What is exact difference between 'YYYY' and 'yyyy'. I read in this link, it states that A common mistake is to use YYYY. yyyy specifies the calendar year whereas YYYY specifies the year (of “Week of Year”), used in the ISO year-week calendar. In most cases, yyyy and YYYY yield the same number, however they may be different. Typically you should use the calendar year. But when I try to use NSString *stringDate = @"Feb 28, 2013 05:30pm"; NSDateFormatter *dateFormatter = [[NSDateFormatter alloc]

How can I convert string date to NSDate?

蓝咒 提交于 2019-12-16 20:52:28
问题 I want to convert "2014-07-15 06:55:14.198000+00:00" this string date to NSDate in Swift. 回答1: try this: let dateFormatter = NSDateFormatter() dateFormatter.dateFormat = /* find out and place date format from * http://userguide.icu-project.org/formatparse/datetime */ let date = dateFormatter.dateFromString(/* your_date_string */) For further query, check NSDateFormatter and DateFormatter classes of Foundation framework for Objective-C and Swift, respectively. Swift 3 and later (Swift 4

How can I convert string date to NSDate?

别来无恙 提交于 2019-12-16 20:51:08
问题 I want to convert "2014-07-15 06:55:14.198000+00:00" this string date to NSDate in Swift. 回答1: try this: let dateFormatter = NSDateFormatter() dateFormatter.dateFormat = /* find out and place date format from * http://userguide.icu-project.org/formatparse/datetime */ let date = dateFormatter.dateFromString(/* your_date_string */) For further query, check NSDateFormatter and DateFormatter classes of Foundation framework for Objective-C and Swift, respectively. Swift 3 and later (Swift 4

do I have to release the NSDate in this code below?

时光怂恿深爱的人放手 提交于 2019-12-14 03:54:57
问题 do I have to release the NSDate in this code below? (i.e. or is it the case that it's just created within a method as a local variable that I don't have to worry) The reason I ask is when I run XCode Profiler and click on one of the points where memory is jumping up, it highligted this bit of code (i.e. the first line in the attached code below) - i.e. I'm looking at the "Leaks Blocks" table in the profiler.. -(NSDate *) dateBySettingHour:(NSInteger)hour andMinute:(NSInteger)minute { // Get

How to get NSDateComponents between two NSDateComponents?

徘徊边缘 提交于 2019-12-14 03:36:48
问题 I've two NSDateComponents , I want all NSDateComponents in between those two, I've tried the following, NSDateComponents *first = ...; NSDateComponents *second = ...; BOOL boolDone = NO; while (!boolDone) { [array addObject:first]; first.day+=1; NSLog(@"%@",first); if([[first date] compare:[second date]] == NSOrderedSame) { boolDone = YES; } } NSLog(@"All dates : %@",array); After the loop, it just prints the date I've in first NSDateComponent ...!! What's wrong? Here's a log to understand

iOS: Compare two less or equal NSDates [duplicate]

馋奶兔 提交于 2019-12-14 03:35:57
问题 This question already has answers here : iOS: Compare two dates (6 answers) Closed 6 years ago . I want to compare two dates and do something when one is less or equal than the other, I tried to do it this way: if ([self.system.systemInbetriebnahme compare:date] == NSOrderedDescending) return nil; But this removes the case when they are both equal is there a way to compare dates with >= ? Thank you More details: I have a date taken from a double dimension array, and i have a date stored in

Issue with NSDate from NSDateComponents

怎甘沉沦 提交于 2019-12-14 03:28:56
问题 i have a string like 2013-03-05T07:37:26.853 and i want to get the Output : 2013-03-05 07:37:26 . I want the final output in NSDate object. i am using below function to convert desire output. and it returning wrong time. - (NSDate *) getDateFromCustomString:(NSString *) dateStr { NSArray *dateStrParts = [dateStr componentsSeparatedByString:@"T"]; NSString *datePart = [dateStrParts objectAtIndex:0]; NSString *timePart = [dateStrParts objectAtIndex:1]; NSArray *dateParts = [datePart

a date string without year to NSDate with year

删除回忆录丶 提交于 2019-12-14 03:09:57
问题 I have a date string of "5:09 pm Wed Sep 2",which is coming from server. when converting the string into NSDate . "2000-09-02 17:09:00 +0000" but the year should have been "2015" like: "2015-09-02 17:09:00 +0000" Here is my code please let me know where is the problem NSString *dateStr = @"5:09 pm Wed Sep 2"; // Convert string to date object NSString *dateFormat= ([self hasAMPM])?@"hh:mm a EEEE MMM d":@"hh:mm a EEEE MMM d" ; NSDate * date = [self toLocalTime:[self convertDateFromString

Changing the current date

孤街浪徒 提交于 2019-12-14 03:08:58
问题 I am working with the date in my iPhone development. I need to increase the date by 24 hours from the current date. 回答1: You can use dateByAddingTimeInterval NSDate *currentDate = [NSDate date]; NSDate *datePlusOneDay = [currentDate dateByAddingTimeInterval:(60 * 60 * 24)]; //one day 回答2: Simple: NSDate *tomorrow = [[NSDate date] dateByAddingTimeInterval:86400]; 回答3: you can add an NSTimeInterval. Since this is a double in seconds just add 24*60*60: - (id)dateByAddingTimeInterval: