nsdatecomponents Questions

7

Solved

I have data in the format time: 13:52, 10:30, 11:48 etc I would like to round to the nearest hour. like for 13:52 -> 14:00 , 10:30 -> 11:00 and 11:48 -> 12:00. How can I do that with NSDate? ...
Inflow asked 10/6, 2013 at 7:3

8

Solved

I’m creating a date using NSDateComponents(). let startDate = NSDateComponents() startDate.year = 2015 startDate.month = 9 startDate.day = 1 let calendar = NSCalendar.currentCalendar() let startDa...

1

Solved

I'm trying to use the new Foundation formatters. To format a Date, I can do something like this: Date.now.formatted(.dateTime.hour().minute().second()) // 5:03:17 PM However, I'm trying to use thi...

25

Solved

-(NSDate *)beginningOfDay:(NSDate *)date { NSCalendar *cal = [NSCalendar currentCalendar]; NSDateComponents *components = [cal components:( NSMonthCalendarUnit | NSYearCalendarUnit | NSHourCalend...
Wirework asked 10/11, 2012 at 18:2

4

Solved

I am using the following DateComponentsFormatter in Swift: let formatter = DateComponentsFormatter() formatter.unitsStyle = .positional formatter.allowedUnits = [.hour, .minute, .second] formatter...
Grenadier asked 12/2, 2019 at 1:8

1

Solved

I believe this has been asked several times, but there is no clear answer. There are two ways to schedule temporal notifications: UNCalendarNotification and UNTimeIntervalNotificationTrigger. Sched...

8

Solved

I want to convert server UTC time to local time and vice-versa. Here is my code.. var isTimeFromServer = true var time:String! var period:String! let timeString = "6:59 AM" //Current UTC time if ...
Antonetteantoni asked 15/3, 2017 at 7:20

7

Solved

I am trying calculate the age from birthdayDate in Swift with this function: var calendar : NSCalendar = NSCalendar.currentCalendar() var dateComponentNow : NSDateComponents = calendar.component...
Chokecherry asked 10/8, 2014 at 19:4

1

I want to print, e.g., the value 1.5 as "1.5 sec", like Safari's timeline does, and I'm trying to use DateComponentsFormatter for it. Unfortunately, its .allowedUnits only goes down to .second (ev...

2

Solved

I am trying to get only date that means hours, mins, seconds are zeroes. This is what i am trying extension Date { var onlyDate: Date? { get { let calender = Calendar.current var dateComponen...
Fagot asked 15/4, 2019 at 11:47

4

Solved

I need to get the weekday of the first day of the month. For example, for the current month September 2013 the first day falls on Sunday.
Liberate asked 17/9, 2013 at 21:31

4

Solved

Question Why is string nil? let formatter = NSDateComponentsFormatter() let referenceDate = NSDate(timeIntervalSinceReferenceDate: 0) let intervalDate = NSDate(timeInterval: 3628810, sinceDate: r...

4

Solved

In my app, I have to set up a weekly reminder so that an alert goes off at the same day/time, a week from now. I have been using NSDateComponenents.week = 1 and adding that to an NSDate, using NSCa...
Deaver asked 20/8, 2014 at 7:39

4

Solved

I have this function : private func getCurrentDateComponent() -> NSDateComponents { let date = NSDate() let calendar = NSCalendar.currentCalendar() let components = calendar.components(.Calen...
Cubiform asked 8/7, 2015 at 8:42

4

Solved

I have in the past used the below function to add on a specific time interval using NSDateComponents to an existing date. (NSDate *)dateByAddingComponents:(NSDateComponents *)comps toDate:(NSDat...
Rafflesia asked 13/1, 2015 at 2:54

1

Solved

I am trying to get date components from a date value from an API endpoint. I need to preserve the date values as they are already adjusted for time zone. Unfortunately, I have no control over how t...
Eisenstein asked 14/11, 2017 at 19:29

3

Solved

I know how to get local date and time, but what I want to do is getting the date and time from different places. For example, I want to find out what the time and date is in New York. How can i sol...
Byram asked 13/11, 2017 at 18:40

2

I have checked the iOS 10 Home app. The screenshot is captured from Home app only. Since last 2 days I have been trying to implement the HMTimerTrigger repeat functionality. My requirement is I ha...
Schaeffer asked 12/8, 2016 at 7:10

6

Solved

I have this subset of a method that needs to get day one of the current month. NSDate *today = [NSDate date]; // returns correctly 28 february 2013 NSCalendar *gregorian = [[NSCalendar alloc] init...
Beatification asked 28/2, 2013 at 10:0

4

Solved

I am trying to check if a particular day exists in a month or not. However unable to find anything of help. To give an example I tried below code in Playground; var components = DateComponents() c...
Tradespeople asked 17/7, 2017 at 7:22

17

Solved

How can I get the year/month/day of a NSDate object, given no other information? I realize that I could probably do this with something similar to this: NSCalendar *cal = [[NSCalendar alloc] init]...
Scaphoid asked 12/9, 2010 at 12:45

7

Hello I have a problem with setting a firstWeekDay, here is what I do: NSCalendar *gregorian = [[NSCalendar alloc] initWithCalendarIdentifier:NSGregorianCalendar]; comp = [gregorian components:(N...
Tour asked 18/3, 2011 at 7:34

4

Solved

I want two NSInteger year, month to go one month back. e.g. now is 2011-01 how can I get 2010-12. adding is one thing, but I want to subtract. NSDate *date = [NSDate date]; NSDateComponents *dateC...
Joy asked 6/1, 2011 at 3:9

2

Solved

I have the following Swift (Swift 3) function to make a date (Date) with date components (DateComponents). func makeDate(year: Int, month: Int, day: Int, hr: Int, min: Int, sec: Int) -> NSDate ...
Poulard asked 8/1, 2017 at 14:32

4

Solved

How do I get the NSDateComponents of a single NSDate? I don't want the components of the difference between 2 dates, just the seconds, minutes, hours, day, month and year of a NSDate?
Wismar asked 25/6, 2011 at 15:17

© 2022 - 2025 — McMap. All rights reserved.