nscalendar

Calculate time elapsed between pressing the same button twice

本秂侑毒 提交于 2019-12-13 07:17:29
问题 I've tried all the time calculating examples I found on this site but somehow I'm getting 0 as value every time. I'm new to IOS and the NSDate is giving me a run for it's money :) I want to record time A when I press button "startStop", and then record time B when I press it again. Pressing it a second time (deselecting) has to calculate the time elapsed between these 2 dates. So far I have this: -(IBAction)buttonClick { NSDate *startStopDate = [NSDate alloc]; NSDateFormatter *formatter= [

Changing background according to time - Objective C

て烟熏妆下的殇ゞ 提交于 2019-12-12 13:04:58
问题 So what I'm trying to do is change the background of an image according to the time of day, but it's running into a problem. Here's the code: -(void)updateBackground { NSDate *currentTime = [NSDate date]; NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init]; [dateFormatter setDateFormat:@"hh:mm a"]; [dateFormatter setTimeStyle:NSDateFormatterShortStyle]; NSString *resultTime = [dateFormatter stringFromDate:currentTime]; [timeLabel setText:resultTime]; NSString *morningStart =

FSCalender Events Show in swift

為{幸葍}努か 提交于 2019-12-12 03:35:23
问题 I am new to swift, Am using Fscalender in swift it's working fine, But I want add the Events to Fscalender, I can get events from Json I Want Display the events in calender, I can try some of the code but its not working getting some errors pls help how to display events in calender var EventsData = [Event]() all events are stored Into Event fileprivate lazy var dateFormatter2: DateFormatter = { let formatter = DateFormatter() formatter.dateFormat = "yyyy-MM-dd" return formatter }() inside

Swift - Get next date from a array of weekdays

南笙酒味 提交于 2019-12-12 02:14:31
问题 Context I'm making an app where I have tasks with due dates and once they are done I want to set a new due date for according to a new date according to a day of the week repeat pattern chosen by the user. Im saving due dates as Date. Im saving the repeat pattern as Int32 (1 for Sunday, 2 for Monday, 4 for Tuesday...) but I can easily get it to an array of Strings or numbers representing each day Problem How do I get the next due date as Date (so I can repeat the task)? Example if I have a

NSDate for the same local time as another NSDate in different time zones

我的梦境 提交于 2019-12-11 13:53:48
问题 I have a date time: Friday, July 8, 2016 at 6:30:00 PM India Standard Time I want a date time like this: Friday, July 8, 2016 at 6:30:00 PM Central Daylight Time I do not want to convert the dates using NSDateFormatter from one timezone to another, because this conversion will give me Friday, July 8, 2016 at 8:00:00 AM Central Daylight Time I want the same date time, but in a different timezone. How can I do that? 回答1: dasblinkenlight's answer is absolutely correct, but I'll explain a little

Get weeks date in IOS SDK

本小妞迷上赌 提交于 2019-12-11 09:44:02
问题 I want to get the current & next week dates with day name. i.e. If today's date is 28-06-2013 (Friday) then I want to get the dates from 23-06-2013(sunday) to 29-06-2013 (Saturday) as the this current week. for next week I want to get dates from 30-06-2013(sunday) to 06-07-2013 (saturday). How can I do this? Thank you, 回答1: Here is sample code that does the trick. -(NSArray*)daysThisWeek { return [self daysInWeek:0 fromDate:[NSDate date]]; } -(NSArray*)daysNextWeek { return [self daysInWeek:1

Why does `ordinality(of: .day, in: .era, for: date)` give the same result for 2 dates in different time zones?

我与影子孤独终老i 提交于 2019-12-11 06:43:25
问题 Consider the following code: import UIKit let date = Date() guard let nycTimeZone = TimeZone(abbreviation: "EST"), let nzTimeZone = TimeZone(abbreviation: "NZDT") else { fatalError() } var nycCalendar = Calendar(identifier: .gregorian) nycCalendar.timeZone = nycTimeZone var nzCalendar = Calendar(identifier: .gregorian) nzCalendar.timeZone = nzTimeZone let now = Date() let nycDayOfEra = nycCalendar.ordinality(of: .day, in: .era, for: now) let nycDayOfYear = nycCalendar.ordinality(of: .day, in:

NSCalendar months range

空扰寡人 提交于 2019-12-11 06:04:00
问题 This code NSDateComponents *component = [[NSDateComponents alloc] init]; NSCalendar *gregorian = [[NSCalendar alloc] initWithCalendarIdentifier:NSGregorianCalendar]; [component setMonth:1]; [component setYear:2013]; [component setDay:1]; currentMonth = [gregorian dateFromComponents:component]; NSLog(@"Date in MonthView %@ ",currentMonth); gives to me the following date Date in MonthView 2012-12-31 23:00:00 +0000 Why? The months range is supposed to go from 0 to 11 ? 回答1: No, months go from 1

How to convert from NSDate(timeIntervalSince1970 to NSDate()?

末鹿安然 提交于 2019-12-11 04:35:20
问题 This is my code. But an error said, cannot invoke dateComponent with an argument list of type... let fromDate = NSDate(timeIntervalSince1970: TimeInterval(tweetsArray[indexPath.row].timestamp)!) let toDate = NSDate() let components : NSCalendar.Unit = [.second, .minute, .hour, .day, .weekOfMonth] let differenceOfDate = NSCalendar.current.dateComponents(components, from: fromDate, to: toDate) 回答1: In Swift 3, NSCalendar.current returns a Calendar , which is the Swift value wrapper type for the

Error combining NSCalendarUnit with OR (pipe) in Swift 2.0

末鹿安然 提交于 2019-12-11 03:51:21
问题 I have some code that's breaking in Swift 2.0: let formatter = NSDateComponentsFormatter() formatter.allowedUnits = NSCalendarUnit.Year formatter.allowedUnits |= .Month formatter.allowedUnits |= .WeekOfMonth formatter.allowedUnits |= .Day formatter.allowedUnits |= .Hour formatter.allowedUnits |= .Minute I get the error Binary operator '|=' cannot be applied to 'NSCalenderUnit' operands . What's the new way of doing this kinda thing? 回答1: NSCalendarUnit is an OptionSetType in Swift 2, instead