gpt4 book ai didi

swift - 如何在 Swift 中从字符串中拆分日期?

转载 作者:行者123 更新时间:2023-11-28 12:15:43 25 4
gpt4 key购买 nike

如何从 "\u200c2017-09-10" 等字符串中仅拆分 "2017-09-10"

days = "\u200c2017-09-10" 
let formatter = DateFormatter()
formatter.dateFormat = "yyyy-MM-dd"
date = formatter.date(from: days)

date 未拆分时返回nil

最佳答案

试试这个:

days = "\u200c2017-09-10"
let last10 = String(days.characters.suffix(10))

输出:2017-09-10

基本上您只需要字符串天数的最后 10 个字符。

关于swift - 如何在 Swift 中从字符串中拆分日期?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46702018/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com