0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

【Go】MySQLのTimestamp型カラム(日本時間が入ってる)をtime.TimeにするとUTCになってしまうのを対応する

Posted at

こんにちは:smiley:

MySQLのTimestamp型カラムに2020-03-12 15:00:00(日本のおやつの時間!)が入っていて、それをGo言語のコードでtime.Time型として取ってくると"2020-03-12 15:00:00 +0000 UTC"になってしまう。

あるとおもいます。

それを期待通りの値に直す小ネタです。

例.go

	tempTime := dbResults[0].CreatedAt
	location := time.FixedZone("JST", 9*60*60)
	tempTime = tempTime.In(location).Add(-9*time.Hour)
	log.Print(tempTime)
  • 強引にJSTに変換します。
  • そのとき勝手に9時間足されてしまうので、自前で引き直します。

2020/03/16 19:44:57 2020-03-12 15:00:00 +0900 JST

やったぜ。

0
0
0

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
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?