nsdateformatter

Date from String using NSDateFormatter regardless 12h-24h setting

北慕城南 提交于 2019-12-22 09:39:56
问题 Today my question is about date formats and strings. My application downloads some strings representing dates from the internet. The date format is always like this: "2010-05-24 at 20:45" I need to convert this string into an NSDate object in order to perform some date manipulations. I tried this code: NSString * dateString = @"2010-05-24 at 20:45" // actually downloaded from the internet NSDateFormatter * myDateFormatter = [[NSDateFormatter alloc] init]; [myDateFormatter setDateFormat:@"yyyy

how to get start and end time of today's date in ios? [duplicate]

三世轮回 提交于 2019-12-22 04:01:43
问题 This question already has answers here : NSDate beginning of day and end of day (21 answers) Closed 3 years ago . I am getting current date and time by using this code let today: NSDate = NSDate() let dateFormatter: NSDateFormatter = NSDateFormatter() dateFormatter.timeStyle = NSDateFormatterStyle.MediumStyle dateFormatter.dateFormat = "yyyy-MM-dd hh:mm:ss" dateFormatter.timeZone = NSTimeZone(abbreviation: "SGT"); print(dateFormatter.stringFromDate(today)) but i want to get start time and end

Date is getting changed while converting to NSDate from NSString

一曲冷凌霜 提交于 2019-12-22 00:09:34
问题 I am converting NSString to NSDate with help of NSDateFormatter. Now code works fine here in all OS with device & simulator but it is creating different Output at UK, USA region. Here is the code that I am using. NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init]; [dateFormatter setDateFormat:@"yyyy-MM-dd HH:mm:ss"]; NSString *dateString=[NSString stringWithString:@"2010-09-05 04:00:00"]; NSDate *dateObj = [dateFormatter dateFromString:dateString]; Actual date is : 2010-09-05 04

NSDateFormatter returns null for specific dates

霸气de小男生 提交于 2019-12-21 12:37:41
问题 I'm having a problem with the NSDateFormatter . It is returning null for some specific dates. I did this function to debug the case: - (void) debugTest:(NSString *)dateStr{ NSLog(@"String: %@", dateStr); NSDateFormatter *df = [[NSDateFormatter alloc] init]; [df setDateFormat:@"yyyy-MM-dd"]; NSDate *dateObj = [df dateFromString: dateStr]; NSLog(@"Date: %@", dateObj); } This is my log output for some dates: String: 2012-10-18 Date: 2012-10-18 03:00:00 +0000 String: 2012-10-19 Date: 2012-10-19

NSDateFormatter returns null for specific dates

浪子不回头ぞ 提交于 2019-12-21 12:35:14
问题 I'm having a problem with the NSDateFormatter . It is returning null for some specific dates. I did this function to debug the case: - (void) debugTest:(NSString *)dateStr{ NSLog(@"String: %@", dateStr); NSDateFormatter *df = [[NSDateFormatter alloc] init]; [df setDateFormat:@"yyyy-MM-dd"]; NSDate *dateObj = [df dateFromString: dateStr]; NSLog(@"Date: %@", dateObj); } This is my log output for some dates: String: 2012-10-18 Date: 2012-10-18 03:00:00 +0000 String: 2012-10-19 Date: 2012-10-19

NSDateFormatter issue involving week numbers

六眼飞鱼酱① 提交于 2019-12-21 10:51:21
问题 On my machine (regional settings United States), the default "short" date format is set to "1/5/13" (month/day/year). In the System Preferences, I have appended to it a week number, "1/5/13 1". My problem is this code, where I try to convert a string to a date: NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init]; [dateFormatter setDateStyle:NSDateFormatterShortStyle]; NSDate *date = [dateFormatter dateFromString:@"1/5/13 1"]; NSLog(@"Date: %@", date); On my machine, this prints:

NSDateFormatter relative date formatting with custom format

荒凉一梦 提交于 2019-12-21 07:34:24
问题 So my intention is to put out dates that would look like the following: Today, August 28 Tomorrow, August 29 Friday, August 30 ...etc The issue is that it seems I can only get so close. When I setDoesRelativeDateFormatting:YES and setDateStyle to Full and setTimeStyle to None , it yields results like this: Today Tomorrow Friday, August 30, 2013 This yields the year and does not yield month and date for today and tomorrow. The other code I've tried is this: [NSDateFormatter

How change the date format which is stored in string? Objective c [duplicate]

痞子三分冷 提交于 2019-12-21 06:08:09
问题 This question already has answers here : Closed 8 years ago . Possible Duplicate: how to convert datetime format in NSString? I have stored date in string from json parsing. The format of date is 2011-1-24. Now i want to convert into MM-dd-YYYY format. For that i am using this code NSString *stringDate =[NSString stringWithFormat:@"%@",[list_date objectAtIndex:indexPath.row]]; NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init]; [dateFormatter setDateFormat:@"MM-dd-yyyy"]; NSDate

How change the date format which is stored in string? Objective c [duplicate]

不问归期 提交于 2019-12-21 06:07:04
问题 This question already has answers here : Closed 8 years ago . Possible Duplicate: how to convert datetime format in NSString? I have stored date in string from json parsing. The format of date is 2011-1-24. Now i want to convert into MM-dd-YYYY format. For that i am using this code NSString *stringDate =[NSString stringWithFormat:@"%@",[list_date objectAtIndex:indexPath.row]]; NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init]; [dateFormatter setDateFormat:@"MM-dd-yyyy"]; NSDate

Objective-C: Unicode Date Format

筅森魡賤 提交于 2019-12-21 04:48:21
问题 I am trying to work out how to have the UNICODE representation of Sun, 03 May 2009 19:58:58 -0700 as eee, dd MMM yyyy HH:mm:s ZZZZ or something. I can't seem to get this working precisely. 回答1: Use an NSDateFormatter. It lets you set a particular format string, using the format specifiers from the Unicode spec, then get the formatted date from a given NSDate object using stringFromDate:. Also consider reading Apple's doc about formatting dates. Example: // Given some NSDate *date