nsdateformatter

DateFormater error only when running on iOS 13

为君一笑 提交于 2020-01-24 20:59:31
问题 I have a function to convert string to date format. This function works as expected on iOS 12 but on iOS 13. I get this error: "Thread 1: Fatal error: Unexpectedly found nil while unwrapping an Optional value" Here is my code: func ConvertDateAndTimeFormat2() { let timeDate = "2019-09-24 15:00:00 +0000" let dateFormatter = DateFormatter() dateFormatter.dateFormat = "yyyy-MM-dd HH:mm:ss +zzzz" dateFormatter.timeZone = TimeZone(abbreviation: "GMT+3:00") var dateObj:Date! dateObj = dateFormatter

How to get start date and end date of the current month (Swift 3)

二次信任 提交于 2020-01-23 07:00:29
问题 I'm trying to get the start and end dates of the current month in dd/MM/yyyy format. I tried using extension as answered in this SO Question.But it seems like it's not what I want(the format is different and also it's giving me last month's last date and current month last but one date ). Can some one help me. Extension Class: extension Date { func startOfMonth() -> Date? { let comp: DateComponents = Calendar.current.dateComponents([.year, .month, .hour], from: Calendar.current.startOfDay(for

dateFromString() returns incorrect date

有些话、适合烂在心里 提交于 2020-01-21 14:39:12
问题 I'm trying to convert string to Date, but it result incorrect date. let dateFormatter = NSDateFormatter() dateFormatter.dateFormat = "dd MMM YYYY" let dt = dateFormatter.dateFromString("17 Sep 2015") println("Date : \(dt)") It result Date : Optional(2014-12-20 18:30:00 +0000) Please let me know where I'm making mistake. I tried other format too, but it return nil. 回答1: The format for year is incorrect, it should be yyyy , not YYYY . "Y": Year (in "Week of Year" based calendars). This year

NSDateFormatter is returning null for date in ios 4.3.3

我与影子孤独终老i 提交于 2020-01-17 05:10:49
问题 I am converting string to date and again to string. using following code NSString *newDate =[NSString stringWithFormat:@"%@",[(Jobs *)[tableArray objectAtIndex:indexPath.row]Date]]; NSLog(@"New Date is %@",newDate); NSDateFormatter *dateFormat = [[NSDateFormatter alloc] init]; [dateFormat setDateFormat:@"MM/dd/yyyy h:mm:ss a"]; NSDate *myDate = [dateFormat dateFromString:newDate]; [dateFormat setDateFormat:@"MM/dd/yyyy"]; NSString *str = [dateFormat stringFromDate:myDate]; NSLog(@"DAte is %@"

Unable to parse date from string using NSDateFormatter [closed]

不羁的心 提交于 2020-01-16 18:39:34
问题 This question is unlikely to help any future visitors; it is only relevant to a small geographic area, a specific moment in time, or an extraordinarily narrow situation that is not generally applicable to the worldwide audience of the internet. For help making this question more broadly applicable, visit the help center. Closed 6 years ago . I am stuck for a while parsing date in string using NSDateFormatter Date in string is in below format 1/1/2011 12:00:00 AM Below is the code I use to

cocoa touch NSDateFormatter and epoch date

匆匆过客 提交于 2020-01-16 02:55:06
问题 I have a string that is (I think) an epoch date. Here is the example string: 1372620996 Heres part of the code: NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init]; NSDate *offerDate = [dateFormatter dateFromString:@"1372620996"]; This returns a null date, and I'm pretty sure my problem is because I haven't set a dateStyle on my NSDateFormatter. However, I'm not sure what dateStyle to use for an epoch date. 回答1: It's actually simpler than that to convert to an NSDate; NSString

How to convert string value into date in iPhone?

ぐ巨炮叔叔 提交于 2020-01-15 11:11:46
问题 I want convert string value into date in my project because I am fetching XML value from web. In XML file I get weather condition and there all value in this weather condition I get current date but my forecastcondition is not come in date it comes in string value, like this: friday saturday and sunday Like this value are come in my forecast condition day this string value come in Day_of_week [Day_of_week] means it shows like this: friday,saturday,sunday How can I convert this string value

format NSString to NSDate

妖精的绣舞 提交于 2020-01-14 05:28:24
问题 i take the user date from facebook , it look like "birthday_date" = "03/04/1987" i wrote this code NSDateFormatter *dateFormatter = [[[NSDateFormatter alloc] init] autorelease]; [dateFormatter setDateFormat:@"dd/MM/YYYY"]; NSDate *dateFromString = [dateFormatter dateFromString:birthDate]; NSLog(@"dateformstring %@ ",dateFromString); [birthPicker setDate:dateFromString animated:YES]; and the result date from string si : 1988-12-25 23:00:00 +0000 , i have this date selected in the picker , I do

converting date to correct format

て烟熏妆下的殇ゞ 提交于 2020-01-11 11:54:07
问题 I've a webservice which gives back my date in the following way. Wed Oct 31 11:59:44 +0000 2012 But I want it to give it back in this way 31-10-2012 11:59 I know that it should be done with a NSDateFormatter. But I don't now how to implement it in the correct way. I've something like this. NSDateFormatter *dateFormatter = [[NSDateFormatter alloc]init]; [dateFormatter setDateFormat:@"dd/MM/yyyy"]; [dateFormatter setTimeZone:[NSTimeZone timeZoneWithAbbreviation:@"GMT+0:00"]]; NSDate *date =

How to change format of date/time?

夙愿已清 提交于 2020-01-11 11:37:38
问题 I have this date and time format: 2010-05-19 07:53:30 and would like to change it to: Wednesday @ 7:53PM 5/19/2010 I'm doing this, which gets the current format: NSDateFormatter *formatter = [[NSDateFormatter alloc] init]; formatter.dateFormat = @"yyyy-MM-dd HH:mm:ss"; but when I change the format, I end up with a null. For example: formatter.dateFormat = @"hh:mm tt MM-dd-yyyy"; date = [formatter stringFromDate:formattedDate]; date will be null. I want to put the end result into an NSString.