jjzjj

DateComponents

全部标签

ios - 如何以编程方式计算 ios 中当前日期的下一个第 5 个工作日期

您好,我使用了NSDateComponents但无法计算第5个日期NSDate*now=[NSDatedate];NSCalendar*calendar=[[NSCalendaralloc]initWithCalendarIdentifier:NSGregorianCalendar];NSDateComponents*dateComponents=[calendarcomponents:NSWeekdayCalendarUnit|NSHourCalendarUnitfromDate:now];NSIntegerweekday=[dateComponentsweekday];NSLog(

ios - iOS 上的冬至日期

我正在组装一个应用程序,该应用程序在夏至和冬至时都利用了太阳的位置。虽然那里有大量数据表,但我想知道是否有任何标准iOS组件可用于计算或检索冬至日期,而无需嵌入然后查找数据。 最佳答案 从评论中吸取建议,以下是我为从儒略日期中获取带有小时和分钟的公历日期而实现的方法。-(NSDate*)dateFromJulianDate:(double)julianDate{NSCalendar*gregorianCalendar=[[NSCalendaralloc]initWithCalendarIdentifier:NSGregorianCa

objective-c - 从引用 NSDate 获取下一周的 NSDate?

给定一个引用日期,我需要找到下面的“星期三”。需要说明的是,如果引用日期是星期二,那么它应该返回同一周的星期三。如果引用日期是星期三或更晚,则需要返回从下周开始的下一个星期三。重要的是它不会返回引用日期之后的星期三。我一直在考虑使用NSDateComponents但不确定如何获得必须始终在未来的一周中的第二天。这是我目前所拥有的:NSDate*referenceDate=[NSDatedate];NSCalendar*calendar=[[NSCalendaralloc]initWithCalendarIdentifier:NSGregorianCalendar];NSDateComp

ios - 为特定日期和时间设置本地通知 swift 3

在我的应用中,我想添加本地通知。该场景将是用户可以选择从周一到周日的任何时间和日期。例如,如果用户选择星期一、星期四和星期六作为日期,时间选择晚上11:00,那么现在应该在所有选定的日期和特定时间通知用户。代码:letnotification=UNMutableNotificationContent()notification.title="DangerWillRobinson"notification.subtitle="SomethingThisWayComes"notification.body="Ineedtotellyousomething,butfirstreadthis.

ios - 如何检查 NSDate 是否在本周?

如何检查NSDate是否在一年中的当前一周?我在下面尝试过,但上周的日期也在“Dateisinthisweek”条件内。-(NSInteger)thisW:(NSDate*)date{NSCalendar*gregorian=[[NSCalendaralloc]initWithCalendarIdentifier:NSGregorianCalendar];NSDateComponents*todaysComponents=[gregoriancomponents:NSWeekCalendarUnitfromDate:[NSDatedate]];NSUIntegertodaysWeek=

iOS 从当前日期起一个月。

我想从当前日期算起一个月。下面是我所拥有的,它正在返回:4027-09-2416:59:00+0000。当前日期是正确的。这是怎么回事?//GettodaysdatetosetthemonthlysubscriptionexpirationdateNSDate*currentDate=[NSDatedate];NSLog(@"CurrentDate=%@",currentDate);NSDateComponents*dateComponents=[[NSCalendarcurrentCalendar]components:NSMonthCalendarUnit|NSDayCalenda

ios - 将 NSDate 格式化为 DDMMYYYY?

我必须从日期发送DDMMYYY日期才能与API通信。NSDateComponents*日期组件;NSCalendar*公历;NSDate*日期;gregorian=[[NSCalendaralloc]initWithCalendarIdentifier:NSGregorianCalendar];dateComponents=[[NSDateComponentsalloc]init];self.date=[gregoriandateByAddingComponents:dateComponentstoDate:[NSDatedate]options:0];我必须使用[dateCompon

ios - 创建具有特定时间的 NSDate

我有以下问题。我需要从特定时间创建一个NSDate对象。在给定的时区(有时是CST、EST等),今天的时间是下午6点。不是每天下午6点,而是今天在该特定时区的下午6点。我正在考虑使用NSCalendar对象来创建特定的日期/时间,但问题是它需要日、月和年。那么当我没有正确的日期时如何设置这些值。示例:今天是2014年1月28日,中部时间11:09。现在,如果我需要创建一个NSCalendar对象,我将需要日、月和年。我不能使用NSDate对象的日、月和年计算,因为它会导致边缘情况出现问题。谁能指出我正确的方向? 最佳答案 试用NSD

ios - 如何检查数组中连续的工作日

我下面有一个函数(datesCheck)循环遍历一组日期,如果一天超过一个,则首先删除所有条目,然后检查数组中的日期是否连续,返回连续的天数当前日期。funcdatesCheck(_dateArray:[Date])->Int{letcalendar=Calendar.currentletuniqueDates=NSSet(array:dateArray.map{calendar.startOfDay(for:$0)}).sorted{($0asAnyObject).timeIntervalSince1970>($1asAnyObject).timeIntervalSince1970}

swift - 如何防止 DateComponents 更新时区

我正在尝试从API端点的日期值中获取日期组件。我需要保留日期值,因为它们已经针对时区进行了调整。不幸的是,我无法控制API如何返回日期值。当我从API获取日期值(sessionTime)时,返回如下:2017-12-0508:00:00+0000我需要根据该时间设置本地通知,但是,当我尝试使用以下代码从该日期对象中提取组件时:letnotifyTime=Calendar.current.dateComponents([.year,.month,.day,.hour,.minute,.second],from:sessionTime)我明白了:year:2017month:12day:5