Reputation: 872
I have a timestamp which I am getting using time.Now().Format(time.RFC3339)
. The format is 2018-10-17T07:26:33Z
However, I want the format in ISO 8601: 2018-10-17T07:26:33.000Z
How do I get those extra milliseconds in the end ?
Upvotes: 5
Views: 10129
Reputation: 34447
make a custom layout as shown below
package main
import (
"fmt"
"time"
)
func main() {
t1, e := time.Parse(
time.RFC3339,
"2018-10-17T07:26:33Z")
if e != nil {
fmt.Println(e)
}
//2018-10-17T07:26:33.000Z required
//Layouts must use the reference time Mon Jan 2 15:04:05 MST 2006
fmt.Println(t1.Format("2006-01-02T15:04:05.000Z"))
}
playground link (good idea Sunny) https://play.golang.org/p/Y3II7lGZB-D
Upvotes: 8
Reputation: 16
use
t := time.Now()
var fdatevalue string
// outstr = fmt.Sprintf("%02d%02d%02d%02d%02d", t.Month(), t.Day(), t.Hour(), t.Minute(), t.Second())
fdatevalue=fmt.Sprintf("%02d%02d%2dT%2d:%2d:%2d", t.Year() , t.Month(), t.Day() , t.Hour(),t.Minute(),t.Second)
Upvotes: -3