nsdate

Wrong date comes back from NSDateComponents

一笑奈何 提交于 2019-11-29 18:13:44
Why is this giving me the wrong date ? NSCalendar *myCalendar = [[NSCalendar alloc] initWithCalendarIdentifier: NSGregorianCalendar]; NSDateComponents* components = [myCalendar components:NSYearCalendarUnit|NSMonthCalendarUnit|NSDayCalendarUnit fromDate:[NSDate date]]; [components setYear:2013]; [components setMonth:06]; [components setDay:28]; [components setHour:5]; [components setMinute:00]; NSDate *startDate1 = [myCalendar dateFromComponents:components]; NSLog(@"start date is %@",startDate1); start date is 2013-06-28 03:00:00 +0000 EDIT What I want to do is the following. I have a start

Adding days to NSDate

老子叫甜甜 提交于 2019-11-29 18:10:34
问题 I want add days to a date, I got many codes for this but none of them are working for me below shown is my code,please somebody help me to fix this issue int daysToAdd=[[appDlegateObj.selectedSkuData objectForKey:@"Release Time"] intValue]; NSTimeInterval secondsForFollowOn=daysToAdd*24*60*60; NSString *dateStr=[contentDic objectForKey:@"Date"]; NSDateFormatter *dateFormatter=[[NSDateFormatter alloc]init]; [dateFormatter setDateFormat:@"yyyy-MM-dd"]; NSDate *dateFromString=[[NSDate alloc]init

Date string to NSDate swift

∥☆過路亽.° 提交于 2019-11-29 17:36:17
i'm having an array fill with date string, which i would like to go through and check whether the date is today or yesterday. The date string could look like following: 2015-04-10 22:07:00 So far i've tried just to convert it using dateFormatter, but it keeps returning nil var dateString = arrayNews[0][0].date as NSString var dateFormatter = NSDateFormatter() dateFormatter.dateFormat = "yyyy-MM-dd hh:mm:ss" var date = dateFormatter.dateFromString(dateString as String) println(date) the sudo code i would like to look something like this if dateString == currentDate date = "Today, hh:mm" else if

How to format convert the string 2013-01-27T02:31:47+08:00 into NSDate

拈花ヽ惹草 提交于 2019-11-29 17:02:18
I have tried many times to convert the string 2013-01-27T02:31:47+08:00 into NSDate. I have found the formatting guide by apple and copied its code and tried , but it doesn't work. NSDateFormatter *rfc3339DateFormatter = [[NSDateFormatter alloc] init]; NSLocale *enUSPOSIXLocale = [[NSLocale alloc] initWithLocaleIdentifier:@"en_US_POSIX"]; [rfc3339DateFormatter setLocale:enUSPOSIXLocale]; [rfc3339DateFormatter setDateFormat:@"yyyy'-'MM'-'dd'T'HH':'mm':'ss'Z'"]; [rfc3339DateFormatter setTimeZone:[NSTimeZone timeZoneForSecondsFromGMT:8]]; // Convert the RFC 3339 date time string to an NSDate.

NsDate formatter giving wrong Date from String [duplicate]

谁说胖子不能爱 提交于 2019-11-29 16:06:51
This question already has an answer here: NSDate Format outputting wrong date 5 answers I have the following code which takes a NSString and returns NSDate. I have copied this code from a project in which it runs perfectly fine - but some how this gives me the wrong output - (NSDate *)dateFromString:(NSString *)date { static NSDateFormatter *dateFormatter; if (!dateFormatter) { dateFormatter = [[NSDateFormatter alloc] init]; [dateFormatter setDateFormat:@"dd-MM-yyyy"]; } NSLog(@"Date: %@ Formatted: %@",date,[dateFormatter dateFromString:date]); return [dateFormatter dateFromString:date]; } and

NSString to NSDate conversion problem

℡╲_俬逩灬. 提交于 2019-11-29 15:50:12
问题 I am having a NSString object which I am converting to NSDate with help of NSDateFormatter. Now code works fine here with all the OS but it is creating different Output at client's add (USA region). Here is the code that I am using. NSDateFormatter *formate = [[[NSDateFormatter alloc] init] autorelease]; [formate setDateFormat:@"yyyy-MM-dd HH:mm:ss"]; NSString *strConcat = @"2010-09-24 17:30:00"; NSDate *date = [formate dateFromString:strConcat]; NSLog(@"Output :%@",date); Output at my end --

Create NSDate for today at a particular hour and minute

风流意气都作罢 提交于 2019-11-29 15:38:19
问题 How can I create an NSDate with today's date and an hour, minutes, and seconds of 5, 0, and 0 respectively? I.e. the date will be 07/02/2010 05:00:00 回答1: //Gives us the current date NSCalendar *gregorian = [[NSCalendar alloc] initWithCalendarIdentifier:NSGregorianCalendar]; NSDateComponents *components = [gregorian components:NSYearCalendarUnit | NSMonthCalendarUnit | NSDayCalendarUnit fromDate:[NSDate date]]; [components setHour:5]; NSDate * date = [gregorian dateFromComponents:components];

NSDate date method returns wrong result

心已入冬 提交于 2019-11-29 14:50:26
I know there is a lot of questions of this type, but I did't find solution for my case; I need to get current and correct NSDate object, not NSString ! This code returns wrong time (+3 hours), because I'm from Ukraine. NSDate *currentDate = [NSDate date]; How to get current NSDate object from NSDateFormatter ? I know only how to get NSString , but I don't need it. EDIT: I'm using this code to compare 2 NSDates using NSCalendar object, here is code: NSCalendar *calendar = [NSCalendar currentCalendar]; NSUInteger unitFlags = NSDayCalendarUnit | NSHourCalendarUnit | NSMinuteCalendarUnit |

Changing Gregorian Month and Days names to Islamic? NSDate

ⅰ亾dé卋堺 提交于 2019-11-29 14:25:24
问题 I'm trying to display the Islamic current day name , month name. I used NSLocale to set the region to ar_SA , however it's just translating the day and month names from English to Arabic. Output I'm getting in Arabic: ١٢ الأحد ، اكتوبر ، ٢٠١٢ which in English is Sunday, October 28, 2012 Output I want: Al-Ahad, Dul-Hijja 12, 1433 Snippet: NSDateFormatter *islamicFormatter = [[NSDateFormatter alloc]init]; [islamicFormatter setDateStyle:NSDateFormatterFullStyle]; [islamicFormatter setLocale:[

NSDateFormatter not giving me correct

不羁岁月 提交于 2019-11-29 13:07:59
I am displaying time. It will show me :TIME :2012-06-18 23:00:00 +0000 But after using NSDateFormatter I do not know why it is giving me 00:00:00 AM NSDateFormatter* dateFormatter = [[NSDateFormatter alloc] init]; [dateFormatter setDateFormat:@"HH:mm:ss a"]; NSLog(@"TIME :%@",self.startDate); NSDate *date = [NSDate date]; NSString * _startTime = [dateFormatter stringFromDate:date]; NSLog(@"current time : %@",_startTime); NSString * _startTime1 = [dateFormatter stringFromDate:self.startDate]; NSLog(@"Start time : %@",_startTime1); [dateFormatter release]; **Result is** TIME :2012-06-18 23:00:00