斯威夫特:在“特定日期"之前获得 30 天

编程入门 行业动态 更新时间:2024-10-10 14:30:12
本文介绍了斯威夫特:在“特定日期"之前获得 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 天

本文发布于:2023-10-17 09:34:13,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1500477.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:斯威夫特   日期   quot

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!