本文介绍了斯威夫特:在“特定日期"之前获得 30 天的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我在显示特定日期时遇到问题.在这种情况下,我的 API (06/16/2015) 有一个随机日期,该日期总是在变化.我把它放入变量名 toDate 与 Date 类型.我需要在 toDate 之前为我的 fromDate 变量获取 30 天.
I have a problem about showing specific date. Here the case, I have a random date from my API (06/16/2015) that always change. I put it into variable name toDate with Date type. I need to get 30 days before the toDate for my fromDate variable.
我阅读了这个 但它仍然无法正常工作.注意:我在这个控制器中没有任何 DatePicker.
I read this but it's still not working. Note: I don't have any DatePicker in this controller.
推荐答案给你:
let toDate = `your date object` let fromDate = Calendar.current.date(byAdding: .month, value: -1, to: toDate) or, // If you want to have exactly 30 days before let fromDate = Calendar.current.date(byAdding: .day, value: -30, to: toDate)更多推荐
斯威夫特:在“特定日期"之前获得 30 天
发布评论