Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

proposal: time: add constants for DatetimeMilli, DatetimeMicro, and DatetimeNano Formats #62090

Open
chenmingyong0423 opened this issue Aug 17, 2023 · 1 comment
Labels
Milestone

Comments

@chenmingyong0423
Copy link

Problem Description

Currently, the Go time package lacks predefined constants to represent datetime formats with millisecond(e.g., 2006-01-02 15:04:05.000), microsecond(e.g., 2006-01-02 15:04:05.000000), and nanosecond(e.g., 2006-01-02 15:04:05.000000000) precision. This requires developers to manually write format strings when they need to use these datetime formats.

Solution

I propose adding three constants in the time package to represent the "2006-01-02 15:04:05.000", "2006-01-02 15:04:05.000000", and "2006-01-02 15:04:05.000000000" datetime formats, making it convenient for developers to use in their projects.

Example

These constants could be named DatetimeMilli, DatetimeMicro, and DatetimeNano, and developers could use them as follows:

formattedTimeMilli := time.Now().Format(time.DatetimeMilli)
formattedTimeMicro := time.Now().Format(time.DatetimeMicro)
formattedTimeNano := time.Now().Format(time.DatetimeNano)
@gopherbot gopherbot added this to the Proposal milestone Aug 17, 2023
@seankhliao
Copy link
Member

back in #52746 we didn't see we widespread use of such formats, has anything changed in that regard?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
Status: Incoming
Development

No branches or pull requests

3 participants