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

Goの日付フォーマットでミリ秒の末尾0を省略しない書式

More than 5 years have passed since last update.

time - The Go Programming Language
に日付フォーマットがいくつか定義してあります。

RFC3339Nano = "2006-01-02T15:04:05.999999999Z07:00"

はナノ秒まで出るので、これを参考に"2006-01-02T15:04:05.999Z07:00"とすればミリ秒になったのですが、末尾のゼロは取り除かれます。つまり0.120秒の場合は.12になります。

書式フォーマットで9の代わりに0を指定して"2006-01-02T15:04:05.000Z07:00"とすれば、.120になります。ログの書式ではこちらのほうが私は好みです。

package main

import (
    "fmt"
    "time"
)

func main() {
    t := time.Date(2013, 9, 2, 1, 55, 20, 120e6, time.Local)
    fmt.Println(t.Format("2006-01-02T15:04:05.999Z07:00"))
    fmt.Println(t.Format("2006-01-02T15:04:05.000Z07:00"))
}
2013-09-02T01:55:20.12Z
2013-09-02T01:55:20.120Z

と出力されます。

http://play.golang.org/p/Dvhhb7GLgR
で試せます。

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