草庐IT

dateFormatter3

全部标签

swift - dateFormatter.dateFromString - 模拟器和 Apple TV 上的不同结果

在AppleTV上,结果是“dateNOTformatted...”在模拟器上,结果是“日期格式...”importUIKitclassViewController:UIViewController{@IBOutletweakvarresultLabel:UILabel!overridefuncviewDidAppear(animated:Bool){letlastModifiedDate="Sun,01May201600:46:17GMT"letdateFormatter=NSDateFormatter()dateFormatter.dateFormat="EEE,ddMMMyyyy

nsdateformatter - 在 iOS Swift 中初始化之前使用的变量 'dateFormatter'

我在使用Swift语言的项目中使用NSDateFormatter。我收到以下错误:Variable'dateFormatter'usedbeforebeinginitialized我的代码:vardate:NSDate=(NSDate.date())vardateFormatter:NSDateFormatterdateFormatter.dateFormat="dd:mm:yyyyHH:mm:sszzz" 最佳答案 只改变一行。你没有初始化NSDateFormatter更改以下行:vardateFormatter:NSDateFo

swift - 如何配置 DateFormatter 以捕获微秒

iOSDate()以至少微秒的精度返回日期。我通过调用Date().timeIntervalSince1970检查了这条语句,结果是1490891661.074981然后我需要将日期转换为精度为微秒的字符串。我按以下方式使用DateFormatter:letformatter=DateFormatter()formatter.dateFormat="yyyy-MM-dd'T'HH:mm:ss.SSSSSSZZZZZ"print(formatter.string(from:date))结果是“2017-03-30T16:34:21.075000Z”现在如果我们比较两个结果:1490891

python - 轴标签的 Matplotlib DateFormatter 不起作用

我正在尝试调整x轴的日期刻度标签的格式,以便它只显示年和月的值。根据我在网上找到的内容,我必须使用mdates.DateFormatter,但它在我当前的代码中根本没有生效。有人看到问题出在哪里吗?(日期是pandasDataframe的索引)importmatplotlib.datesasmdatesimportmatplotlib.pyplotaspltimportpandasaspdfig=plt.figure(figsize=(10,6))ax=fig.add_subplot(111)ax.xaxis.set_major_formatter(mdates.DateFormatt

python - 轴标签的 Matplotlib DateFormatter 不起作用

我正在尝试调整x轴的日期刻度标签的格式,以便它只显示年和月的值。根据我在网上找到的内容,我必须使用mdates.DateFormatter,但它在我当前的代码中根本没有生效。有人看到问题出在哪里吗?(日期是pandasDataframe的索引)importmatplotlib.datesasmdatesimportmatplotlib.pyplotaspltimportpandasaspdfig=plt.figure(figsize=(10,6))ax=fig.add_subplot(111)ax.xaxis.set_major_formatter(mdates.DateFormatt

iOS 11.2.6 DateFormatter.date 对于遵守巴西利亚夏令时的城市返回 nil

这个问题在这里已经有了答案:DateFormatter'sreturnsnilforspecificdatestringswithouttimeinSwift(1个回答)关闭2年前。我从头开始创建了一个新的SingleViewApp项目,并仅将以下代码添加到ViewController的viewDidLoad方法中:letdateFormatter=DateFormatter()dateFormatter.dateFormat="MM/yy"ifletdate=dateFormatter.date(from:"11/20"){print("gotthedate:\(date)")}el

iOS 11.2.6 DateFormatter.date 对于遵守巴西利亚夏令时的城市返回 nil

这个问题在这里已经有了答案:DateFormatter'sreturnsnilforspecificdatestringswithouttimeinSwift(1个回答)关闭2年前。我从头开始创建了一个新的SingleViewApp项目,并仅将以下代码添加到ViewController的viewDidLoad方法中:letdateFormatter=DateFormatter()dateFormatter.dateFormat="MM/yy"ifletdate=dateFormatter.date(from:"11/20"){print("gotthedate:\(date)")}el

ios - ISO8601DateFormatter 不解析 ISO 日期字符串

我正在尝试解析这个2017-01-23T10:12:31.484Z使用iOS10提供的原生ISO8601DateFormatter类,但总是失败。如果字符串不包含毫秒,则创建Date对象没有问题。我尝试了这个和许多选项组合,但总是失败...letformatter=ISO8601DateFormatter()formatter.timeZone=TimeZone(secondsFromGMT:0)formatter.formatOptions=[.withInternetDateTime,.withDashSeparatorInDate,.withColonSeparatorInTim

ios - ISO8601DateFormatter 不解析 ISO 日期字符串

我正在尝试解析这个2017-01-23T10:12:31.484Z使用iOS10提供的原生ISO8601DateFormatter类,但总是失败。如果字符串不包含毫秒,则创建Date对象没有问题。我尝试了这个和许多选项组合,但总是失败...letformatter=ISO8601DateFormatter()formatter.timeZone=TimeZone(secondsFromGMT:0)formatter.formatOptions=[.withInternetDateTime,.withDashSeparatorInDate,.withColonSeparatorInTim

swift - 在 Unix 时间戳上使用 DateFormatter

我在运行时遇到崩溃,它指向dateFormmater.timezone。控制台中的错误是:Couldnotcastvalueoftype'Swift.Optional'(0x1192bf4a8)to'NSTimeZone'(0x1192c0270).rowEvents.date的值为"1480134638.0"我试图从保存为字符串的Firebase中提取Unix时间戳。将其转换为日期并再次将其保存为字符串,以便我可以将其发布到单元格标签上。我从StackOverflow获得了这段代码。我插入了我的数据,在我运行它之前一切都很好。我想一切都不是很好......ifletlastUpdat