Home > Backend Development > Golang > How to Get Unix Time in Milliseconds Using Go?

How to Get Unix Time in Milliseconds Using Go?

Barbara Streisand
Release: 2024-12-11 17:16:15
Original
818 people have browsed it

How to Get Unix Time in Milliseconds Using Go?

Converting Unix Time in Go to Milliseconds

How can we obtain the Unix time in milliseconds using Go? To elaborate, consider the following function:

Our objective is to reduce precision and work solely with milliseconds.

As of Go version 1.17, the time package has been enhanced with the UnixMicro() and UnixMilli() functions, rendering the following approach the preferred option:

For Go versions 1.16 and earlier, the following solution suffices:

In this case, we divide by 1e6 (1,000,000), the number of nanoseconds in a millisecond.

To visualize the output, we can create an example program:

Upon running this program, you will witness the Unix time displayed in milliseconds.

The above is the detailed content of How to Get Unix Time in Milliseconds Using Go?. For more information, please follow other related articles on the PHP Chinese website!

source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Latest Articles by Author
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template