- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我试图从 UIDatePicker
获取小时和分钟值以用于我的服务器,但 UIDatePicker
的值是一个小时。我本地的时区目前使用夏令时,所以我假设 UIDatePicker
不遵守这一点。
这是我用来将 UIDatePicker
提供的日期转换为其小时和分钟值的代码:
struct MyTimeSettings {
var time: Date!
init(from json: [String : Any]) {
var calendar = Calendar.current
calendar.timeZone = TimeZone(abbreviation: "UTC")!
self.time = calendar.date(from: DateComponents(timeZone: TimeZone(abbreviation: "UTC")!, year: 0, month: 0, day: 0, hour: (json["Hour"] as! Int), minute: (json["Minute"] as! Int)))
}
init() {}
func getJSON() -> [String : Any] {
var calendar = Calendar.current
calendar.timeZone = TimeZone(abbreviation: "UTC")!
let components = calendar.dateComponents(in: TimeZone(abbreviation: "UTC")!, from: self.time)
return [
"Hour" : components.hour!,
"Minute" : components.minute!
]
}
static func ==(lhs: MyTimeSettings, rhs: MyTimeSettings) -> Bool {
return (lhs.time == rhs.time)
}
}
为了测试它,我给了它一个 Date
,计算结果为美国东部时间晚上 10:15:
var settings = MyTimeSettings()
let date = Date(timeIntervalSince1970: 1522894500)
settings.time = date
print(settings.getJSON()) // ["Hour": 2, "Minute": 15]
它也适用于输入 JSON:
let json = ["Hour": 2, "Minute": 15]
print(MyTimeSettings(from: json).getJSON()) // ["Hour": 2, "Minute": 15]
我的问题是相同的代码在从 UIDatePicker
获取日期时不能正常工作。我正在使用 Eureka用于在表格 View 单元格中显示 UIDatePicker
的库:
<<< TimePickerRow() { row in
row.cell.datePicker.timeZone = TimeZone.current
row.cell.datePicker.locale = Locale.current
row.value = self.myTimeSettings.time
}.onChange({ (row) in
self.myTimeSettings.time = row.value
})
然后我将日期选择器上的时间设置为晚上 10 点 15 分(美国东部时间),但我没有得到世界标准时间凌晨 2 点 15 分:
print(myTimeSettings.getJSON()) // ["Hour": 3, "Minute": 12]
为什么日期选择器返回错误的时间?
最佳答案
根据 Apple's Documentation你会想调用这个方法:
Declaration
func daylightSavingTimeOffset(for date: Date = default) -> TimeInterval
Parameters
date
The date to use for the calculation. The default value is the current date.
关于ios - UIDatePicker 不遵守夏令时,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49650476/
根据 PEP 257命令行脚本的文档字符串应该是它的用法信息: The docstring of a script (a stand-alone program) should be usable a
我有一个使用 exit 的批处理文件命令返回退出代码。 在某些情况下,该批处理文件可以从命令行以交互方式调用,或者在其他情况下,可以使用 Exec 作为 MSBuild 项目的一部分运行。任务。 如果
以下内容使 nginx 不传递到 PHP-FPM fastcgi 服务器,因为我创建了一个位置 block : location = /test.php { auth_basic "Nope.
java bean 命名标准是否有可能有助于实现封装? 访问修饰符不是有助于封装吗? 最佳答案 没有。命名标准不会做、开放或限制任何事情。对于封装,您当然需要访问修饰符。最好是两者都使用。即使您有一段
在 mysql Ver 14.14 Distrib 5.1.66 上,对于未知的 linux-gnu (x86_64),存在未遵守/遵守 MySQL 外键约束的问题。 数据库/表结构从未被修改过,又名
收到一封来自 Apple 的关于应用更新截止日期的电子邮件 更多信息 - link 作为开发人员需要在 iOS13 SDK 的代码库中进行哪些更改我已经更改了目标并构建了应用程序,除此之外我们还必须实
我有一个生成 IAsyncEnumerable 的异步迭代器方法(数字流),每 200 毫秒一个数字。此方法的调用者使用流,但希望在 1000 毫秒后停止枚举。所以一个CancellationToke
我是 Swift 开发的新手,在尝试做一些教程时遇到了困难(我知道,它们是一步一步的,但显然我一定在某个地方搞砸了,现在我无法弄清楚为什么它不起作用。我不太擅长调试,并且对该语言的基础缺乏扎实的理解。
有点愚蠢的问题。例如我读过,在 C11 中添加了对线程的支持。然后,例如我的STM32F4的GCC编译器说,它支持C11标准。那么,这是否意味着现在没有操作系统我将获得线程支持???但这怎么可能呢?
我的网站使用 zurb Foundation。它已经得到了自己的验证。这是a link到文档。 我使用以下代码来验证并提交我的表单数据。 $('#myForm').on('valid', functi
我知道 ansible 支持这种形式的模板中的循环: {% for host in groups['all'] %} "{{ host }}"{% if not loop.last %},{% e
我很困惑 time-based cache policies使用 HttpWebRequest 时工作。 我正在调用 WebAPI 的 GET 方法,该方法返回 JSON 内容以及类似于以下内容的 C
我正在使用 zurb foundation 5 和 abide js 检查我的表单。我必须检查 DATE1 是否早于或等于 DATE2 如何使用 abidejs 检查它是否有效? 最佳答案 简短的回答
我有一个非常简单的 javascript 构造函数,如下所示: function DisplayedTableData() { this.rowData = []; } SonarQube 提
我有一个 div 嵌套在两个 div 中。最外层和最内层的 div 都有固定的宽度。我想将最外层的 div's width 设置为 0,这样它的所有子项也都将为 0,或者至少不可见。 但是当我将最外面
我们使用 GSLB 进行地理分布和负载平衡。每个服务都分配了一个固定的域名。通过一些 DNS 魔术,域名被解析为最接近负载最少的服务器的 IP。为了使负载均衡发挥作用,应用服务器需要遵守来自 DNS
我正在编写一个向 REST API 服务发出频繁请求的 Android 应用程序。此服务的硬请求限制为每秒 2 个请求,之后它将返回 HTTP 503,没有其他信息。我想成为一名优秀的开发人员并限制我
ScalaTest 的输出是彩色的以区分不同的状态,但这些最终作为控制代码和 [34m Annoying garbage 有没有办法说服 Eclipse 控制台尊重或忽略这些序列,或者插入一个 Vie
我对 Node.js 比较陌生,我试图通过编写一个简单的模块来更熟悉它。该模块的目的是获取 ID、抓取网站并返回包含数据的字典数组。 网站上的数据分散在各个页面上,而每个页面都通过 URI 中的不同索
我正在通过 gradle/maven 使用 slf4j-android 1.6.1-RC1,当我在模拟器中运行应用程序时,当我在 Android Studio 0.3.5 下调用 Log.debug
我是一名优秀的程序员,十分优秀!