Questions tagged [nsdatecomponents]

NSDateComponents is a class in Apple's Cocoa and CocoaTouch frameworks which represents either a date or a period of time as composed of several elements -- days, hours, and months, for example.

NSDateComponents encapsulates the components of a date in an extendable, object-oriented manner.

Resources:

567 questions
0
votes
1 answer

How to modify dates with NSDateComponents

I have this string which is passed to this method to produce 2 times: Mon thru Friday 7:00 AM - 10:00 PM And I use this code to split up the string into two times; opening and closing times: -(void)dealWithTimeStrings2:(NSString*)timeString{ …
marciokoko
  • 4,988
  • 8
  • 51
  • 91
0
votes
5 answers

Convert A NSString into NSDate to add days to the dynamic date

I am getting a NSString(in which i have a date)from database, I need to add days like suppose 10//12/15/45/60 days to the date, How can I do it. when I am trying with this piece of code : NSString *expiryDateStr = [NSString…
iOSDev
  • 412
  • 10
  • 30
0
votes
3 answers

How to format in NSDate depending on the time difference?

I want to display a date in the following way: If it is today, then display the time only. If it is in the past week, then display "Yesterday", "Sunday", "Monday" etc. If it is more than one week ago, then display the actual date. I am trying…
Jeff
  • 1,405
  • 3
  • 26
  • 46
0
votes
1 answer

What is an NSCalendarCalendarUnit?

That's not a typo (at least not on my part, anyways.) One of the defined NSCalendarUnits are a NSCalendarCalendarUnit. Can anyone explain what that is or how you would use it? For example, I'd like to calculate the number of days between dates,…
ArtOfWarfare
  • 20,617
  • 19
  • 137
  • 193
0
votes
0 answers

Converting date string by replacing the current year give wrong result

I have NSString with value "29/01/2010" Which I want to convert into NSDate with replacing the year value with the current year. For that I have tried with NSCalendar *calendar = [[NSCalendar alloc]…
Heena
  • 2,348
  • 3
  • 32
  • 58
0
votes
1 answer

Showing wrong date when using NSIndianCalendar

I am trying to get date from week day and year . It work and get correct Output. But when i am changing CalendarIdentifier then it will show wrong output. Here is my code when i am setting CalendarIdentifier is NSGregorianCalendar NSCalendar…
Kalpesh
  • 5,336
  • 26
  • 41
0
votes
1 answer

Update a Label daily with new text

I have a label I want to update daily and automatically? in some specific time. How could the code be.. I have searched every where about how to updating the label daily. the NSdate and NStimer label working . And also datepicker if the user want to…
0
votes
2 answers

Not getting correct date from string

I am using following code to get a date from string but its not showing correct date NSDateFormatter *saveddf = [[NSDateFormatter alloc] init]; [saveddf setDateFormat:@"EEEE_MMMM dd_YYYY hh:mm a"]; [saveddf setTimeZone:[NSTimeZone…
0
votes
1 answer

NSDateComponents possible timezone bug?

Wonder if I've found a bug with NSDateComponents. When using NSDateComponents to calculate dates and switching between time zones, it's possible to get the wrong date on the simulator (not tested on device). It seems that it's the right offset, but…
0
votes
0 answers

NSDateComponents returns wrong date (off by 10 days)

So I use this method to convert a string to NSDate. Hours before, it works correctly, but suddenly the NSDateComponents returns a wrong date. I have no clue why. - (NSDate *)NSDateFromDate: (NSString *) str { NSDateFormatter *formatter =…
harinsa
  • 3,176
  • 5
  • 33
  • 53
0
votes
2 answers

Difference between dates with NSDateComponents gives wrong output

I'm trying to get the difference between two dates and it should be displayed in days. NSLog(@"%@", [NSDate date]); NSDateFormatter *formatter = [[NSDateFormatter alloc] init]; [formatter setDateFormat:@"dd/mm/yyyy"]; NSDate *formattedDate =…
förschter
  • 740
  • 1
  • 7
  • 24
0
votes
3 answers

NSDate of the week

I an using the current methods to get the first and the last day of the current week: NSDate *weekDate = [NSDate date]; NSCalendar *myCalendar = [[NSCalendar alloc] initWithCalendarIdentifier:NSGregorianCalendar]; NSDateComponents *currentComps =…
YosiFZ
  • 7,792
  • 21
  • 114
  • 221
0
votes
3 answers

Convert from just the hours:minutes:timezone to a complete date in another TimeZone

I am retrieving some dates from a remote server. Unfortunately one of the possible formats is just h:mm:a Example of data I downloaded yesterday May, 21, 2013: 1) 04:36PM EDT 2) 11:51PM EDT The data server TimeZone is "America/New_York". My data…
nico9T
  • 2,496
  • 2
  • 26
  • 44
0
votes
2 answers

NSDate wrong output when add day to NSDate

NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init]; [dateFormatter setDateFormat:@"yyyy-MM-dd"]; NSString *dateString = [dateFormatter stringFromDate:[NSDate date]]; NSLog(@"%@",dateString); // Retrieve NSDate instance from…
Dashzaki
  • 568
  • 2
  • 6
  • 13
0
votes
1 answer

Local push notification last day of month

I want to send local push notification last day of every month 12.00. I want someone to check if this is the right code since I don't wanna wait a month to see if it works? Thnx! NSDate *curDate = [NSDate date]; NSCalendar *calendar…
Jojo
  • 490
  • 1
  • 7
  • 22