nsdate

How to Get date from week number and year

时光总嘲笑我的痴心妄想 提交于 2019-12-14 01:48:00
问题 I want to get date from week number and year . i got week number and year from server . I am trying following code but it wont work. NSDateFormatter *dateFormatter2 = [[NSDateFormatter alloc] init]; // this is imporant - we set our input date format to match our input string // if format doesn't match you'll get nil from your string, so be careful [dateFormatter2 setDateFormat:@"yyyy-MM-dd"]; NSDate *now = [dateFormatter2 dateFromString:@"2001-01-01"]; NSCalendar *gregorian1 = [[NSCalendar

need to get central time in objective-c

亡梦爱人 提交于 2019-12-14 00:00:21
问题 I have app where i need to get the current time (CST). I'm trying to use the following code but the NDate is the same as GMT: NSDate* date = [NSDate date]; NSLog(@"Time is %@", [date description]); [NSTimeZone setDefaultTimeZone:[NSTimeZone timeZoneWithAbbreviation:@"CST"]]; NSDate* nDate = [NSDate date]; NSLog(@"Central time is%@", [nDate description]) 回答1: Beside the fact that the time has not timezone itself, but you have to add a calendar to set it in relation to a time zone as I

Convert string with ordinal format to date on iOS

拟墨画扇 提交于 2019-12-13 22:25:44
问题 Possible Duplicate: Converting a string to an NSDate I have date in string and want to convert in NSDate. In string date is: "21st June 2012" How can I convert this in NSDate? Please concentrate on day "21st" not "21" when you give answer. 回答1: You can use NSDateFormatter to change NSString to NSDate. 回答2: There is a generic answer for this kind of questions available on Stack Overflow, it's to use NSDateFormatter in Objective-C / DateFormatter in Swift. And the format is following tr35-19 or

NSCalendar Find Saturday and Sunday of Current Month

家住魔仙堡 提交于 2019-12-13 21:03:08
问题 I am working on project where I want to integrate NSCalendar functionality in my app. Hence I googled and I found this solution. It give me all months in the year and also I can select particular date. that's fine. But I wanted to disable all saturdays and sundays of every month somehow I tried to do it but when I tap previous month or next month it changes the selection. I have gone through almost all stackoverflow questions But I didn't find proper way to do it. I request you to all Is

Conversion from NSDate to NSString with Core-Data Migration on Attribute Not Displaying the String Appropriately

点点圈 提交于 2019-12-13 19:04:42
问题 I'm sorry for the long question; I have no idea how to explain this without including lots of code and images. I am working on updating my app and because I discovered an issue relating to dates, I had to change an Attribute from NSDate to NSString . I'm using Core Data for my application. The model of the application is: Transaction Entity Date Entity Years Entity The Year Entity has an attribute which is called yearOfEvent of type NSDate and with the update to my app (already in the app

iPhone - how may I check if a date is Monday?

允我心安 提交于 2019-12-13 16:08:03
问题 I'm trying to find if a date is Monday. To do this I proceed this way : #define kDateAndHourUnitsComponents NSYearCalendarUnit | NSMonthCalendarUnit | NSDayCalendarUnit | NSHourCalendarUnit | NSMinuteCalendarUnit | NSSecondCalendarUnit NSCalendar *calendar = [NSCalendar autoupdatingCurrentCalendar]; // for test and debug purpose NSDateComponents* b = [calendar components:kDateAndHourUnitsComponents fromDate:retDate]; int a=[[calendar components:kDateAndHourUnitsComponents fromDate:theDate]

NSDate - Changing the year value

点点圈 提交于 2019-12-13 15:10:04
问题 I need to change a NSDate object. What I am basically doing is changing the year value. for example: NSString *someYear = @"2093"; NSDate *date = [NSDate date]; // Gets the current date. ... Create a new date based upon 'date' but with specified year value. So with 'date' returning 2011-03-06 22:17:50 +0000 from init, I would like to create a date with 2093-03-06 22:17:50 +0000. However I would like this to be as culturally neutral as possible, so it will work whatever the timezone. Thanks.

NSDate being saved as timestamp in CoreData

杀马特。学长 韩版系。学妹 提交于 2019-12-13 12:12:11
问题 I currently am saving dates in my iOS application in CoreData. In Core Data, my date attribute is of type "Date". In my NSManagedObjectSubclass file, the attribute is of type: NSDate (which is fine). The date in Core Data is being stored as: 2014/05/16 14:54:51 and when I check the actual values in my SQLite3 navigator, it is being stored in the form: 421959291.293972 for the date How do I get the above value for the date, and is there a way to convert it back to the form: 2014/05/16 14:54:51

NSCalendar date error

為{幸葍}努か 提交于 2019-12-13 11:35:16
问题 I'm trying to use NSCalendar with NSIslamicCalendar identifier. But the day result is not good, her's my code: NSCalendar *calandar = [[NSCalendar alloc]initWithCalendarIdentifier:NSIslamicCalendar]; NSDateComponents *components = [calandar components:(NSDayCalendarUnit | NSMonthCalendarUnit | NSYearCalendarUnit) fromDate:[NSDate date]]; NSInteger theDay = [components day]; NSInteger theMonth = [components month]; NSInteger theYear = [components year]; [components setDay:theDay]; [components

To convert a particular format to NSDate [closed]

烂漫一生 提交于 2019-12-13 11:27:46
问题 Closed. This question is off-topic. It is not currently accepting answers. Want to improve this question? Update the question so it's on-topic for Stack Overflow. Closed 5 years ago . I am getting a date component from web service as @"2014-01-08T00:00:00.000Z". I need to convert it into a date only providing me with year , month and date. Please help 回答1: Use this code to get the Current Date NSDateFormatter *dateFor=[[NSDateFormatter alloc]init]; NSString *currentDateString = @"2014-01