nsdate

iphone how can i get month name from month number? [duplicate]

只谈情不闲聊 提交于 2019-12-20 17:32:14
问题 This question already has answers here : Closed 8 years ago . Possible Duplicate: iOS: How to get a proper Month name from a number? How can I get month name from month number? I have month number like 02 , but would like the month as a string, in this case February . 回答1: Something like this: int monthNumber = 11; NSString * dateString = [NSString stringWithFormat: @"%d", monthNumber]; NSDateFormatter* dateFormatter = [[NSDateFormatter alloc] init]; [dateFormatter setDateFormat:@"MM"];

iOS 8 - get current date as DD/MM/YYYY

我的未来我决定 提交于 2019-12-20 14:12:08
问题 Can anybody give me some code how I get the date? NSDateComponents *components = [[NSCalendarcurrentCalendar] component:NSCalendarUnitDay | NSCalendarUnitMonth | NSCalendarUnitYearfromDate:[NSDatedate]]; NSString *day = [components day]; NSString *week = [components month]; NSString *year = [components year]; NSString *date = [NSString stringWithFormat:@"%@.%@.%@",day,week,year]; ^^ my code is not working :S And is there a way that I can get the date of tomorrow, in 1 week and so on... Thanks

iOS 8 - get current date as DD/MM/YYYY

心已入冬 提交于 2019-12-20 14:11:12
问题 Can anybody give me some code how I get the date? NSDateComponents *components = [[NSCalendarcurrentCalendar] component:NSCalendarUnitDay | NSCalendarUnitMonth | NSCalendarUnitYearfromDate:[NSDatedate]]; NSString *day = [components day]; NSString *week = [components month]; NSString *year = [components year]; NSString *date = [NSString stringWithFormat:@"%@.%@.%@",day,week,year]; ^^ my code is not working :S And is there a way that I can get the date of tomorrow, in 1 week and so on... Thanks

Generate NSDate from day, month, and year [closed]

我只是一个虾纸丫 提交于 2019-12-20 11:01:16
问题 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'm trying to generate a NSDate from a month day and year (all in integer format). Right now my attempt is such: NSCalendar *calendar = [NSCalendar

Where is the extra 75 seconds coming from?

不羁岁月 提交于 2019-12-20 10:58:32
问题 While writing some unit tests on a Julian Day calculator, I found that dates prior to 2nd December 1847 were being initialised incorrectly by NSDate. They appear to have 75 seconds added on. I haven't been able to find anything pointing to that date (which is well after the Gregorian calendar cutoff). Is it a bug or is there a historic calendar adjustment that I've not come across? int main(int argc, const char * argv[]) { @autoreleasepool { NSCalendar *cal = [NSCalendar currentCalendar];

How can I generate convenient date ranges based on a given NSDate?

喜夏-厌秋 提交于 2019-12-20 09:38:18
问题 I'm creating a report generator in Cocoa, and I need to produce convenient date ranges such as "Today", "This Week", "This Month", "This Year", etc. Is there a good way to do this? Here is my skeleton thus far: @interface DateRange : NSObject { NSDate startDate; NSDate endDate; } @property (nonatomic, retain) NSDate * startDate; @property (nonatomic, retain) NSDate * endDate; + (DateRange *)rangeForDayContainingDate:(NSDate *)date; + (DateRange *)rangeForWeekContainingDate:(NSDate *)date; +

Get firstdate, lastdate of month?

谁说我不能喝 提交于 2019-12-20 09:37:28
问题 I want to get firstdate、lastdate of month,I try NSDateComponents *components = [calendar components:units fromDate:[NSDate date]]; [components setDay:1]; self.currentDate = [calendar dateFromComponents:components]; int m = components.month; int y = components.year; int d = components.day; log: 2012,5,1 How can i get lastdate od month? please give me some advice,thank you!! 回答1: Some NSDate category methods I wrote will help you: Here's an easy way to find the start of a month: (NSDate *)

How to convert Unix timestamp into Swift NSDate object? [closed]

别来无恙 提交于 2019-12-20 08:57:39
问题 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'm getting dates as Unix timestamps through my API and I want to convert them into NSDate objects in Swift. How can I do that? 回答1: Try this: var date = NSDate(timeIntervalSince1970: timeInterval) 来源: https://stackoverflow.com/questions/26844132/how-to-convert-unix-timestamp-into-swift-nsdate-object

Get current date in Swift 3? [closed]

十年热恋 提交于 2019-12-20 08:23:58
问题 Closed . This question needs details or clarity. It is not currently accepting answers. Want to improve this question? Add details and clarify the problem by editing this post. Closed 3 years ago . How can I set label.text current date in Swift 3? I want to print just today to the screen. I did not find how to do that. In c# is very simple: var date = DateTime.Now I need to write 15.09.2016 in swift 3. thanks 回答1: You say in a comment you want to get "15.09.2016". For this, use Date and

Subtract 7 days from current date

无人久伴 提交于 2019-12-20 08:08:34
问题 It seems that I can't subtract 7 days from the current date. This is how i am doing it: NSCalendar *gregorian = [[NSCalendar alloc] initWithCalendarIdentifier:NSGregorianCalendar]; NSDateComponents *offsetComponents = [[NSDateComponents alloc] init]; [offsetComponents setDay:-7]; NSDate *sevenDaysAgo = [gregorian dateByAddingComponents:offsetComponents toDate:[NSDate date] options:0]; SevenDaysAgo gets the same value as the current date. Please help. EDIT: In my code I forgot to replace the