nsdateformatter

Date formatter giving wrong date when converting to string Objective-C

非 Y 不嫁゛ 提交于 2020-01-06 14:03:17
问题 I'm converting a date to text to display in a text box and it converts fine. The 29,30 and 31 December 2013 gets converted to 2014 and 29,30 and 31 December 2014 gets converted to 2015. This is my code to convert the date to text NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init]; [dateFormatter setDateFormat:@"dd MMM YYYY"]; self.pickupDateTextField.text = [dateFormatter stringFromDate:[self.datePicker date]]; NSLog(@"%@ %@",self.datePicker.date,self.pickupDateTextField.text);

How to query and convert Parse.com Date to NSDate/String

限于喜欢 提交于 2020-01-06 08:35:08
问题 I want to take the parse column " createdAt ", query it and make it into a string that displays on the UI as a label to show the user when a product was posted and when it expires. There are similar questions on stackoverflow, but none have helped me and all have given me errors and crashes. I am using a TableViewController class and I'm querying 2 things: the productName and the timeCreated . (The productName I'm able to display in a cell without a problem.) I've tried several ways of

NSDateFormatter wrong output with string from stringWithDate:

怎甘沉沦 提交于 2020-01-06 05:48:09
问题 Why does NSDateFormatter misinterpretes his own created dateString? NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init]; [dateFormatter setDateFormat:@"YYYY-MM-DD'T'HH:mm:ss.SSSZZZZ"]; NSDate *now = [NSDate date]; NSLog(@"Now: %@, Date: %@", [dateFormatter dateFromString:[dateFormatter stringFromDate:now]], now); produces the following result: Now: 1970-01-06 18:07:05 +0100, Date: 2010-01-06 18:07:05 +0100 I know that you should use yyyy and dd (and it does not happen with yyyy

string to date in my timeZone make wrong date

风流意气都作罢 提交于 2020-01-06 05:35:38
问题 I'm trying to convert String to date in my country time zone but the result is not as formatted I did let dbl = TimeInterval(longDate) let date = Date(timeIntervalSince1970: dbl / 1000) let formatter = DateFormatter() print(longDate) formatter.calendar = Calendar(identifier: .persian) formatter.locale = Locale(identifier: "fa_IR") formatter.timeZone = TimeZone(identifier: "IRST") formatter.dateFormat = "yyyy-MM-dd HH:mm:ss" let a = formatter.string(from: date) resultDate = dateFormatter.date

What are some possible optimizations for NSDateFormatter's stringFromDate?

回眸只為那壹抹淺笑 提交于 2020-01-05 04:14:20
问题 I am currently profiling my iPhone application start-up in an attempt to get it to start as quickly as possible. In the first 19 seconds of my application being started I call NSDateFormatter's stringFromDate method 6 times with the following format string: @"h:mm a zzz" The NSDateFormatter instance itself is shared by all calls and I only set the date format once, but those 6 calls to stringFromDate amount to 17.3% of my start-up CPU time. Note: The dates are dynamic so I can't just save the

NSDateFormatter time zone abbreviation

隐身守侯 提交于 2020-01-04 14:09:07
问题 I need to recognize date strings like Tue Aug 13 17:29:20 MSK 2013 . And, as I know, to do that I need to use 'V' symbol in NSDateFormmater, but it only recognizes GMT+04:00 like time zones. Is there any other way to parse time zone abbreviation? Here is the code: NSDateFormatter *dft = [[NSDateFormatter alloc] init]; [dft setDateFormat:@"EEE MMM dd HH:mm:ss V yyyy"]; NSLog(@"%@", [dft stringFromDate:[NSDate date]]); NSLog(@"%@", [dft dateFromString:@"Tue Aug 13 17:29:20 MSK 2013"]); Output:

Trim NSDate to show date only

喜欢而已 提交于 2020-01-04 04:04:30
问题 I have been through all the similar questions, unfortunately non could solve my problem so I asked it. I need my function to return an NSDate and only date, but my return value contains timing as well, I have tried the setTimeStyle noStyle and every possible solution I could come up with, here is the code: -(NSDate*)stringToDate{ NSString *dateString = @"01-02-2010"; NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init]; [dateFormatter setDateFormat:@"dd-MM-yyyy"]; NSDate *date;

How to convert date string into format “17 Nov 2010”

流过昼夜 提交于 2020-01-02 23:02:39
问题 I have the date that is in format 2010-11-17 .This is of the form NSString . I want to convert this NSString date into format 17 Nov 2010 and display in a label This date is just not the current date but may even be the older dates. So I cant use the [NSDate date] instance to get the date. I tried using NSDateFormatter with the method dateFromString . But it gives me a null value. Here is the code snippet NSString *dates = @”2010-11-16”; NSDateFormatter *dateFormatter = [[NSDateFormatter

How to get next 10 days from current date in swift

删除回忆录丶 提交于 2020-01-02 00:53:12
问题 I have dateformat string like this "2015-03-09".How do i get next 10 days date from current date?any help will be appreciated.thanks in advance 回答1: For a purely Swift 3 solution: Calendar.current.date(byAdding: .day, value: 10, to: Date()) 回答2: Here's how to get a date 10 days from now, using built-in date modification method .dateByAddingUnit If all 10 days (dates) are required, can be looped by "value:10" part and added to array. var tenDaysfromNow: NSDate { return NSCalendar

NSDateFormatter Question

♀尐吖头ヾ 提交于 2020-01-01 04:28:04
问题 i am using the following code to get the current time.. NSDate *myDate = [NSDate date]; NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init]; [dateFormatter setTimeZone:[NSTimeZone timeZoneWithAbbreviation:@"GMT+0200"]]; // Set date style: [dateFormatter setDateStyle:NSDateFormatterShortStyle]; [dateFormatter setTimeStyle:NSDateFormatterLongStyle]; NSString *GMTDateString = [dateFormatter stringFromDate: myDate]; My problem is : I want the time in HH:MM:SS:(milliseconds if possible