Skip to content

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

@chenmingyong0423

Description

@chenmingyong0423

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)

Metadata

Metadata

Assignees

No one assigned

    Labels

    ProposalWaitingForInfoIssue is not actionable because of missing required information, which needs to be provided.

    Type

    No type

    Projects

    Status

    Incoming

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions