LoginSignup
1
0

More than 1 year has passed since last update.

iOSのNSTimeZoneのUTCってnameがGMTなんだ..

Last updated at Posted at 2022-02-26

GMT_UTC.png

AndroidとiOSでTimeZoneのUTCにまつわる調査をしていたところ想定外の結果になったので書き残しておきます。誰か真相を知っていたら教えて下さい。

GMTとUTCの違い

GMTとUTCの違いをググるとCITIZENの用語集とよくある質問リストが最初に出てくる

両者は、目的も概念も算出方法もまったく異なりますが、日常生活に不都合のない精度の時間測定(整数の秒)であれば、ほぼ差がないと考えて問題ありません。

そう、ほぼ一緒と考えてよいということ。日本のAsia/Tokyo(+9:00)より9時間前のタイムゾーンということだ。

Android(Kotlin)の場合

import java.util.TimeZone

fun main() {
    var tz1 = TimeZone.getTimeZone("Asia/Tokyo")
  	println("The id of Asia/Tokyo is ${tz1.id}")
    
    var tz2 = TimeZone.getTimeZone("UTC")
  	println("The id of UTC is ${tz2.id}")
    
    var tz3 = TimeZone.getTimeZone("GMT")
    println("The id of GMT is ${tz3.id}")
}

結果

The id of Asia/Tokyo is Asia/Tokyo
The id of UTC is UTC
The id of GMT is GMT

idはそれぞれインスタンス化したidがそのまま出力されているので想定どおり。

対して、iOSの場合は..

iOS(Swift)の場合

    func testExample() {
        let tz1 = NSTimeZone(name: "Asia/Tokyo")!
        print("The name of Asia/Tokyo is", tz1.name);
        
        let tz2 = NSTimeZone(name: "GMT")!
        print("The name of GMT is", tz2.name);
        
        let tz3 = NSTimeZone(name: "UTC")!
        print("The name of UTC is", tz3.name)
    }

結果

The name of Asia/Tokyo is Asia/Tokyo
The name of GMT is GMT
The name of UTC is GMT

一番最後のUTCでインスタンス化したtimezoneのnameがGMTになっているのがわかる。
一緒と考えていいといっても、インスタンス化の元に使ったname変えたらダメでしょうに。
これはなんでだ..?
なぜこんな仕様になっているのか知っている人は教えて下さい🙏

1
0
1

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
0