草庐IT

dateFormatter1

全部标签

ios - 如何在 DateFormatters 的日期和时间设置中正确支持 iOS 12 小时/24 小时时间覆盖?

如果您的iOS设备设置为使用默认为12小时制的区域(例如美国)并且您有一个DateFormatter设置如下:vardateFormatter:DateFormatter={letformatter=DateFormatter()formatter.dateFormat="h:mma"returnformatter}()然后,如果在iOS的“设置”中的“日期和时间”中打开“24小时制”开关,它将以24小时格式输出时间。如果您的自定义日期格式是“H:mm”,即24小时制,并且您仍处于默认12小时制区域,那么无论24小时制开关的开/关状态如何,它都会输出24小时制时间.好的,很好,很简单,

swift - 为什么 dateformatter.date() 默认返回 UTC?

我对这种行为感到困惑:letdateFormatter=DateFormatter()dateFormatter.dateFormat="yyyy-MM-ddHH:mm:sszzz"letresult=dateFormatter.date(from:"2017-04-1212:12:12GMT+1")!2017-04-1211:12:12UTC为什么结果会自动转换成UTC?如何获得相同的时区? 最佳答案 Dateobjectsencapsulateasinglepointintime,independentofanyparticul

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