What is wrong with the below GO code? I tried a GO project and deployed in Openshift and everything was fine till yesterday. All of a sudden from today, the time package returns 0
val,_ := strconv.ParseInt(string(time.Now().Unix()),10,64)
println("Time now in openshift :",time.Now().Second())
So basically actual time here is "1969-12-31". Could be the bug in GO.
There is absolutely no need to convert the time to a string by hand, time.Format does this for you. Or, if you want to print out the seconds since epoch, simply use the %d
verb, which is explicitly for printing base10 decimal numbers Run on playground
package main
import "fmt"
import "time"
func main() {
fmt.Printf("Hello, %s
",time.Now().Format(time.RFC3339))
fmt.Printf("Seconds since epoch %d",time.Now().Unix())
}
First of all, why are you using strconv
if Unix
already returns an int64
?
Secondly, string(int)
conversion doesn't do what you think it does. It converts between Unicode code points (aka rune
s) and strings. You need strconv.Itoa
here:
val, _ := strconv.ParseInt(strconv.FormatInt(time.Now().Unix(), 10), 10, 64)
println("Time now in openshift :", val)