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
-1
votes
1 answer

Create a NSDate with timezone

I'm trying to create a date in ios with: NSCalendar *gregorian=[[NSCalendar alloc] initWithCalendarIdentifier: NSGregorianCalendar]; [gregorian setTimeZone:[NSTimeZone systemTimeZone]]; NSDateComponents…
xarly
  • 2,054
  • 4
  • 24
  • 40
-1
votes
2 answers

How do I filter through an NSArray of NSDate objects to find next closest date?

I am trying to figure out how to filter through an NSArray of NSDate objects to find the next closest one (like a bus stop app). The day does not matter whatsoever. All that matters in the NSDate object is the hour and minute since it is the same…
-1
votes
1 answer

NSDate from NSDateComponents: Why I am getting wrong hours and day?

I have a date. NSLog shows it as: 2014-05-11 21:59:59 +0000 Now I want to get the same date but with hour, minutes and seconds set to zero: 2014-05-11 00:00:00 +0000 My code: NSCalendar *calendar = [NSCalendar currentCalendar]; [calendar…
mrd
  • 4,561
  • 10
  • 54
  • 92
-1
votes
4 answers

How to check if a day lies between two other days in iOS...?

I have a date component say birthdayComponent (it has month and day in it) and I want to check if it lies between to other components.. say (beginDaYComponent and endDayComponent). I want to check if my birthday component lies between these two…
Ankit Srivastava
  • 12,347
  • 11
  • 63
  • 115
-1
votes
4 answers

How to compute age from NSDate

I am working on an app that needs to find someones age depending on their birthday. I have a simple NSDate but how would I find this with NSDateFormatter?
random_0620
  • 1,636
  • 5
  • 23
  • 44
-1
votes
2 answers

How do I set the date part for an NSDate time in order to compare times?

I get 7:00AM and 10:00PM as NSStrings from a webservice. I convert them to NSDate using this code block: NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init]; [dateFormatter setDateFormat:@"hh:mm a"]; [dateFormatter…
marciokoko
  • 4,988
  • 8
  • 51
  • 91
-1
votes
3 answers

Issue with NSDate from NSDateComponents

i have a string like 2013-03-05T07:37:26.853 and i want to get the Output : 2013-03-05 07:37:26. I want the final output in NSDate object. i am using below function to convert desire output. and it returning wrong time. - (NSDate *)…
Hitarth
  • 1,950
  • 3
  • 27
  • 52
-1
votes
3 answers

NSdateFormatter in iphone sdk

I am beginner in ios development. I am stuck in NSdateFormatter class. My question is: Which kind of formatter support on this date "Oct, 25th"? Please help me, Thanks in advance...
RaviM
  • 62
  • 14
-1
votes
2 answers

Calculate Year From current NSDate

I want to calculate the year from current NSDate. Suppose my current date 14-06-2012 so, what would be last date after end of year. (In simple way I can explain you that, if I have date 01-01-2012 then after end of year I would get 31-12-2012). So,…
iMash
  • 1,178
  • 1
  • 12
  • 33
-2
votes
1 answer

Why DatetimeComponents are no returning hours, minutes and seconds when converting GMT time

I'm converting date time(2021-10-15 18:30:00 UTC,2021-10-15 18:30:00 +0000) to datetime component but it's missing hours, minutes and seconds let changedDate = Calendar.current.date(byAdding: .day, value: -10, to: actualDate)! var datcomp =…
Amogam
  • 321
  • 5
  • 20
-2
votes
2 answers

How to calculate the days between 2 dates without 31st of any month

Main Goal: I want to count wage based on 30days in every month in month with 31 it should count max 30 days let monthlyWage = someValue let perDay : Double = Double(monthlyWage/30) let components = calendar.dateComponents([.day], from:startDateDay,…
O.Soap
  • 9
  • 4
-2
votes
3 answers

How to fetch day, month and hour from NSDate in Swift

I have an NSDate object called reservationDate and I want to fetch day, month and hour from the Date. However, I'm getting wrong values. How can I get these values? The value of the reservationDate object reservationDate NSDate 2016-08-05 21:00:00…
AfterCoder
  • 731
  • 2
  • 6
  • 22
-2
votes
1 answer

Time Interval between two dates returns nil

I am calculating the time difference between two NSDates and it always returns 0.0000 .I am using the Same logic to calculate the time stamp and have formatted correctly as well .. When I try to log the dates separately , it gets printed correctly…
AnxiousMan
  • 578
  • 2
  • 8
  • 25
-2
votes
1 answer

Objective-C: Create week-day-number to name mapping

EDIT Start Ok, obviously I didn't make myself clear. I need a "first-day-of-the-week"-independent bi-directional mapping of days of the week. So although the user might change his/her locale/region settings the stored day-numbers can still be used…
dergab
  • 965
  • 7
  • 16
-2
votes
1 answer

Get days between days

Before giving downvote, comment the reason I have created a UIDatePicker with minimum & maximum date values (i.e. 6 months of date picker) Now, i need to get 7 days from selected date. There i need to check the conditions, If date is today date i…
Praveenkumar
  • 24,084
  • 23
  • 95
  • 173
1 2 3
37
38