no way to format milliseconds from Time?

7,184 views
Skip to first unread message

AJ ONeal

unread,
Apr 15, 2011, 4:32:09 PM4/15/11
to golang-nuts
I'm a little confused as to why, with all of its awesomeness, GO lacks subsecond support in the Time object.

Is the reason Nanoseconds() is separate for some sort of optimization?

If so, would it be possible to provide at least millisecond support in Time?

Seconds can be, well, a very long time.

AJ ONeal

bflm

unread,
Apr 15, 2011, 5:30:03 PM4/15/11
to golang-nuts
I don't understand from the above what are you missing in the time
package. E.g. the log package deals with sub second resolution and
uses "time", see:
http://golang.org/src/pkg/log/log.go#L84

Or, pease try to show what exactly you are trying to achieve and maybe
you'll get some help here on the list.

AJ ONeal

unread,
Apr 20, 2011, 12:56:54 PM4/20/11
to golang-nuts
I send and receive particular network messages a few times a second with an ISO8601 timestamp in the message, so milliseconds are important.

These don't support sub-second resolution:
I have to manually parse and format my timestamps. :'(

P.S. I'm coming to GO from a background rich with JavaScript and C, and a bit of Ruby, C++, Java, and Python tossed in here and there.

AJ ONeal

Russ Cox

unread,
Apr 20, 2011, 1:04:12 PM4/20/11
to AJ ONeal, golang-nuts
I think it's fair to say that this is a known
shortcoming of the time package. It's due
to be rethought in the coming months.

Russ

AJ ONeal

unread,
Apr 20, 2011, 1:06:44 PM4/20/11
to golang-nuts
I'm glad to hear that! I'll keep an eye out for it.

AJ ONeal

Morgaine

unread,
Apr 21, 2011, 3:55:48 PM4/21/11
to AJ ONeal, golang-nuts
I too have a keen interest in anything to do with timing, mainly from the engineering perspective of intrumenting software.  As they say, "What you don't measure, you don't know, even when you think you do.". :-)  And formatting+parsing time efficiently is part of that interest.

So that's two eyes peering in that direction. :P

Morgaine.


================

mty...@gmail.com

unread,
Jun 20, 2014, 8:10:57 AM6/20/14
to golan...@googlegroups.com, cool...@gmail.com
There is still no millisecond support in http://golang.org/pkg/time/#Time.Format . Am I missing anything?

Jan Mercl

unread,
Jun 20, 2014, 9:17:08 AM6/20/14
to mty...@gmail.com, golang-nuts, cool...@gmail.com
On Fri, Jun 20, 2014 at 2:10 PM, <mty...@gmail.com> wrote:
> There is still no millisecond support in
> http://golang.org/pkg/time/#Time.Format . Am I missing anything?

Eg.: http://play.golang.org/p/IulAKVC_Er

-j

mty...@gmail.com

unread,
Jun 20, 2014, 10:58:40 AM6/20/14
to golan...@googlegroups.com, mty...@gmail.com, cool...@gmail.com
I was looking for a solution to adapt milliseconds to example format: "02/01/2006 - 15:04:05.000 MST" And this works fine.
Reply all
Reply to author
Forward
0 new messages