Help us understand the problem. What is going on with this article?

[Go] UTCの時刻を日本時間に変換する

More than 5 years have passed since last update.

日本でローカルで普通に動かすとtime.Now()はJSTになるのですが、Google App Engineの開発サーバーdev_appserver.pyや http://play.golang.org/ ではUTCになります。

以下のようにすればJSTに変換できます。

package main

import (
    "fmt"
    "time"  
)       

func main() {
    now := time.Now()
    fmt.Println(now.Format(time.RFC3339))

    nowUTC := now.UTC() 
    fmt.Println(nowUTC.Format(time.RFC3339))

    // This fails with "panic: unknown time zone Asia/Tokyo" at play.golang.org
    // jst, err := time.LoadLocation("Asia/Tokyo")
    //if err != nil {               
    //  panic(err)
    //}                                 

    jst := time.FixedZone("Asia/Tokyo", 9*60*60)

    nowJST := nowUTC.In(jst)                        
    fmt.Println(nowJST.Format(time.RFC3339))

    // results at local                                 
    // 2013-09-30T02:21:12+09:00                            
    // 2013-09-29T17:21:12Z
    // 2013-09-30T02:21:12+09:00
    //                                                          
    // results at http://play.golang.org/
    // 2009-11-10T23:00:00Z                                         
    // 2009-11-10T23:00:00Z
    // 2009-11-11T08:00:00+09:00                                        
}

func LoadLocation(name string) (*Location, error)も試してみたのですが、play.golang.org ではAsia/Tokyoはunkown time zoneとエラーになってしまいました。

http://play.golang.org/p/-e7unXO1f9 このリンクをクリックするとGo playgroundで試せます。

Why do not you register as a user and use Qiita more conveniently?
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away
Comments
Sign up for free and join this conversation.
If you already have a Qiita account
Why do not you register as a user and use Qiita more conveniently?
You need to log in to use this function. Qiita can be used more conveniently after logging in.
You seem to be reading articles frequently this month. Qiita can be used more conveniently after logging in.
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away