nsdateformatter

NSDate is not converting correctly using NSDateFormatter

↘锁芯ラ 提交于 2019-12-11 00:51:47
问题 I have the following NSDateFormatter: NSDateFormatter* dateFormatter = [[NSDateFormatter alloc] init]; [dateFormatter setDateFormat:@"MMM. d, yyyy"]; NSLocale *usLocal = [[NSLocale alloc] initWithLocaleIdentifier:@"en_US"]; [dateFormatter setLocale:usLocal]; and I have a while loop which starts at a given start date and increments the date by one until it reaches a specific end date. NSDate *d = start; while(YES){ NSString *td = [dateFormatter stringFromDate:d]; NSLog(@"converted date %@ to %

NSDateFormatter Trouble?

醉酒当歌 提交于 2019-12-10 23:16:52
问题 I am trying to parse an RSS feed, but the date is hard to parse. The date string is: publishedDate = "2013-01-08T20:09:02.000Z" Here is my code: NSDateFormatter *utc = [[NSDateFormatter alloc] init]; [utc setTimeZone:[NSTimeZone timeZoneWithName:@"UTC"]]; [utc setDateFormat:@"yyyy-MM-dd'T'HH:mm:ss'Z'"]; NSDate *dtUTC = [utc dateFromString: publishedDate]; NSDateFormatter *dfLocal = [[NSDateFormatter alloc] init]; [dfLocal setDateFormat:@"yyyy-MM-dd"]; [dfLocal setTimeZone:[NSTimeZone

Covert NSString to NSDate in a different timezone

☆樱花仙子☆ 提交于 2019-12-10 22:47:37
问题 I am trying to convert a string to date in a separate time zone from the current system time zone. I have set the time zone of the dateformatter to this timezone. But the NSDate I get is always in my current time zone. For instance, my current time zone is PDT. I have set the DateFormatter's time zone to CST. I have a string with the time in CST. But when I use date formatter to convert this string to date, I get the date in PDT, whereas I want it in CST. Can someone please help. Thanks. 回答1:

NSDate Formatting

早过忘川 提交于 2019-12-10 21:25:45
问题 I have a date string as follows: "Fri, 17 Jun 2011 19:20:51 PDT" which I need to parse into an NSDate format. NSDateFormatter *dateFormatter = [[NSDateFormatter alloc]init]; [dateFormatter setDateFormat:@"EEE, d MM YYYY HH:mm:ss zzz"]; NSDate *date = [dateFormatter dateFromString:currentPubDate ]; [dateFormatter release]; The code doesn't appear to be working and I am not sure why. I have looked into the issue but searching through forums etc and can't seem to find an answer. I do believe it

remove year for date format in respect to the users locale

此生再无相见时 提交于 2019-12-10 18:34:17
问题 I want to display the day and the month in respect to the locale of the users device. So that the date of today would be displayed as 5/18 with american settings and 18.5. with german setting. As I want to handle every possible locale, I cant just simply use the [dateFormatter setDateFormat:] and [dateFormatter setDateStyle:NSDateFormatterShortStyle] will display the year. Beside trying to identify the year value in the string and removeing it, is there a more elegant way? 回答1: I found the

xcode 4.2 location simulator and Time Zone

二次信任 提交于 2019-12-10 18:22:33
问题 I noticed a nifty setting in the xcode simulator while running that I can change the current location and hence simulate location based tests However, when I try to get the date using NSDateFormatter, the local date is still in PST. I am in the Pacific Time Zone NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init]; [dateFormatter setDateStyle:NSDateFormatterMediumStyle]; // Jan 1, 2010 [dateFormatter setTimeStyle:NSDateFormatterShortStyle]; // 1:43 PM NSLocale *usLocale = [

NSDateFormatter Puzzle! Is this is new Mountain Lion Bug?

 ̄綄美尐妖づ 提交于 2019-12-10 13:43:19
问题 I believe I might have found a bug in NSDateFormatter , and I am not sure if this is localized to having a Brazil time zone specified in System Preferences. A full project is here: http://www.idanfe.com/dl/nsDateFormatterPuzzle.zip The relevant excerpts of the code is shown below: NSArray *unformattedDatesArray = [[NSArray alloc] initWithObjects:@"2011-09-18", @"2011-10-16",@"2011-11-13",@"2011-12-11",@"2012-01-08",@"2012-02-05", nil]; NSString *resultedString = @""; int ii = 0; NSUInteger

Create NSDate with a specific time

雨燕双飞 提交于 2019-12-10 13:27:21
问题 I have the following problem. I need to create an NSDate object from a specific time. The time is 6 pm for today in a given timezone (sometimes CST, EST etc). Not 6 pm for every day, but 6pm for today in that particular timezone. I was thinking of using the NSCalendar object to create the specific date/time but the problem is that it needs a day, month and year. So how do I set these values when I don't have the correct date for it. Example : Today is 28th January 2014, 11:09 in CST. Now if I

Best way to synchronize iPhone time with the server

孤人 提交于 2019-12-10 13:13:21
问题 I have a client server model where server will send some data which has date parameters and iPhone will need to render it. Server and iPhone will resides in different timezones. So I need to synchronize times in both. Let say user has done some activity at "07/18/2011/04 /45/EDT" (server time). From the iPhone end I need to convert this date string into a NSDate object. What is the best way to achieve this. Thank you 回答1: Sorry for the late response, just looked for "NSDate Sync to Server" on

Display NSDates in terms of week

风格不统一 提交于 2019-12-10 11:48:08
问题 Scenario: I have an expense tracking iOS Application and I am storing expenses from a expense detail view controller into a table view (with fetched results controller) that shows the list of expenses along with the category and amount and date. I do have a date attribute in my entity "Money" which is a parent entity for either an expense or an income. Question: What I want is to basically categorize my expenses for a given week, a month, or year and display it as the section header title for