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

Implement strftime #444

Closed
gopherbot opened this issue Dec 18, 2009 · 9 comments
Closed

Implement strftime #444

gopherbot opened this issue Dec 18, 2009 · 9 comments

Comments

@gopherbot
Copy link

by sionide21:

I would like to finish implementing that time.format method and make it
available through time.Strftime.
@rsc
Copy link
Contributor

rsc commented Dec 21, 2009

Comment 1:

Strftime is a kitchen sink, a bad interface: no one remembers
all the letters, so the only way to use it is with documentation
in hand.  At that point you might as well write the longer but
more readable fmt.Sprintf equivalent.
I intentionally hid time.format in favor of a small collection
of commonly-used time formats.  If there is a missing format,
I'd rather add it than expose time.format.

Owner changed to r...@golang.org.

@gopherbot
Copy link
Author

Comment 2 by sionide21:

I agree that Strftime is kind of a pain but it would be nice to have the
compatibility with preexisting languages. It would be much easier to port preexisting
code if you could just copy your time formats over.

@rsc
Copy link
Contributor

rsc commented Jan 8, 2010

Comment 3:

Rob added time.Format instead.

Status changed to WorkingAsIntended.

@gopherbot
Copy link
Author

Comment 4 by crquan:

no, I don't agree strftime is bad, it actually provides same way as date command, then
it's easier to write code as same as shell (call date) and python, I hope this can be
available in Go as well, the date command exists in Unix for decades, why Go language
not willing to provide the same convenience?
date '+%Y%m%d-%H%M%S'
time.strftime('%Y%m%d-%H%M%S')

@davecheney
Copy link
Contributor

Comment 5:

This issue has been closed for over 4 years. The format that the time package is not
going to change in the life of Go 1.

@gopherbot
Copy link
Author

Comment 6 by crquan:

and the time.Format is buggy if I tried to use layout like this: (in Asia culture, we
don't assume people know the the months' English name, so we use all numbers)
        const layout = "20140714-030001"
        fmt.Println(time.Now().Format(layout))
it prints like 180730773-090007, what's the hell of this?
especially in logging functionality, I want to print current time in this format prepend
to every output line, I think the time.Format needs to guess what numbers mean in the
layout string every time, do you think is that efficient?

@robpike
Copy link
Contributor

robpike commented Jul 18, 2014

Comment 7:

It's not buggy and your supposition is wrong. The layout is defined for a specific time,
not any old time. This property is well explained in the documentation. The layout
string you want is
const layout = "20060102-150405"
http://play.golang.org/p/tPjLQd4k14
The issue remains closed and perhaps should have comments disabled.

@robpike
Copy link
Contributor

robpike commented Jul 18, 2014

Comment 8:

The package is not buggy, it works as explained in the documentation, using a format
string that is set to a specific, standard time. Your layout string is wrong; use this:
const layout = "20060102-150405"
http://play.golang.org/p/tPjLQd4k14
The issue remains closed and should perhaps have comments disabled.

@rsc
Copy link
Contributor

rsc commented Jul 18, 2014

Comment 9:

Labels changed: added restrict-addissuecomment-commit.

@golang golang locked and limited conversation to collaborators Dec 8, 2014
@rsc rsc removed their assignment Jun 22, 2022
This issue was closed.
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

4 participants