【问题标题】:Equivelant for [NSTimeZone timeZoneWithAbbreviation: @"GMT"] in swift相当于 [NSTimeZone timeZone With Abbreviation: @"GMT"] in swift
【发布时间】:2014-11-09 17:07:36
【问题描述】:

我需要知道[NSTimeZone timeZoneWithAbbreviation: @"GMT"] 的等效语法 很快

【问题讨论】:

  • 我想通了 var formatter: NSDateFormatter = NSDateFormatter() formatter.timeZone = NSTimeZone(abbreviation: "GMT");
  • 你看过documentation吗?它显示了 Swift 和 Objective-C 方法
  • 是的,谢谢 Martin 我找到了。
  • 是的,那是该代码的精确翻译。或者你也可以使用formatter.timeZone = NSTimeZone(forSecondsFromGMT: 0)
  • 鉴于您已经回答了自己的问题,我可能建议您删除此问题。如果它可能对未来的读者有价值,你可以post an answer to your own question,但在这种情况下,我建议直接删除它。

标签: ios cocoa-touch swift nstimezone


【解决方案1】:

这里:

var formatter: NSDateFormatter = NSDateFormatter()
formatter.timeZone = NSTimeZone(abbreviation: "GMT")

【讨论】:

    【解决方案2】:

    斯威夫特 3

    let dateFormatterUTC = DateFormatter()
    dateFormatterUTC.timeZone = TimeZone(abbreviation: "UTC")
    

    【讨论】:

      猜你喜欢
      • 2021-07-04
      • 2020-10-01
      • 2014-08-22
      • 2012-03-06
      • 2020-05-23
      • 2011-12-28
      • 2011-08-17
      • 2013-02-03
      • 1970-01-01
      相关资源
      最近更新 更多