Skip to content

proposal: runtime, time: add API BuildTimestamp to report an application's build time #23175

Closed
@vipally

Description

@vipally

Use build timestamp to distinguish different version of application binary is a common way in other languages.
eg: C has macros "__DATE__" and "__TIME__" to fetch compiler time.
But golang has no way to achive this feature nowadays.
I have made a patch to provide fllow API to achive it.

runtime.BuildTimestamp defines a buildtimestamp value which will be written by linker(cmd/link).

time.BuildTime() converts runtime.BuildTimestamp() to time.Time.
The expected usage of BuildTimestamp API is as follow:

func main() {
	println("hello world!")
	println("buildtimestamp:", runtime.BuildTimestamp())
	println("buildtime     :", time.BuildTime().String())
	// Output:
	// hello world!
	// buildtimestamp: 1513671919
	// buildtime     : 2017-12-19 16:25:19 +0800 CST
}

It will be my pleasure that if go team can accept this feature in go repository.
The branch

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions