In JavaScript, I can assign:
var now = Date.now();
Then use now
to calculate as a number variable
time.Time
type in Go doesn't seem to meet this demand. What is the Go equivalent of JavaScript's Date.now()
?
Date.now()
returns milliseconds since epoch UTC
The now() method returns the milliseconds elapsed since 1 January 1970 00:00:00 UTC up until now as a Number.
To get that in Go, you can use:
time.Now().UTC().UnixNano() / 1e6
You can use Now function from "time" package as follows:
package main
import (
"fmt"
"time"
)
func main() {
fmt.Println(time.Now())
fmt.Println(time.Now().Date())
}
Sample output:
2009-11-10 23:00:00 +0000 UTC
2009 November 10
Here is function explanation from documentation:
func Now() Time
Now returns the current local time.
func (t Time) Date() (year int, month Month, day int)
Date returns the year, month, and day in which t occurs.
Watch it in Live Demo.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With