Skip to content

proposal: time: add "1136214245" as layout string for unix timestamp #65665

@dpifke

Description

@dpifke

Proposal Details

2006-01-02T15:04:05Z07:00 as a UNIX timestamp (seconds since January 1, 1970) is 1136214245. (In milliseconds, it's 1136214245000; in microseconds, it's 1136214245000000; in nanoseconds, it's 1136214245000000000.)

I propose being able to use these values as layouts with time.Parse. For instance, the result of time.Parse("1136214245", "1707688329") would be Sun, 11 Feb 2024 21:40:11 GMT. These values are unambiguous with the current std string and I believe could be added in a fully reverse-compatible manner.

My motivation is that I have some library code which converts from fmt.Stringer (such as a field from JSON input data) to time.Time by guessing several common layouts. It currently special-cases situations where strconv.ParseFloat succeeds, and then tries to guess the appropriate unit. This could be simplified if the standard library supported these layouts.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions