Last active
September 5, 2024 07:44
-
-
Save rustyeddy/77f17f4f0fb83cc87115eb72a23f18f7 to your computer and use it in GitHub Desktop.
Go filename friendly RFC3339 inspired timestamps
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// GetTimeStamp returns a timestamp in a file name friendly, version of the RFC3339 | |
// format. The string produced by RFC3339 includes a couple colons ':' that are not | |
// friendly to most filenames (unix and dos a like). The colons need to be escaped | |
// if used in a filename, since they are useless, we'll rip em. | |
func TimeStamp() string { | |
ts := time.Now().UTC().Format(time.RFC3339) | |
return strings.Replace(ts, ":", "", -1) // get rid of offensive colons | |
} |
Why not directly time.Now().UTC().Format("20060102T150405Z")
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Result
20091110T230000Z
This way might be better for linux files.