How to create UTC date without extra UTC string

79 views
Skip to first unread message

Alex Mills

unread,
Sep 23, 2020, 2:39:08 PM9/23/20
to golang-nuts
I have this date string:

"2020-09-23 18:31:41.015852841 +0000 UTC"

the above is generated via:

time.Now().UTC().String()

my question is, how can I generate a date string like this:

"2020-09-23 18:31:41.0158"

and how can I then parse it?  I dont need to indicate that it's UTC, I can assume it's UTC.
But I want to include 4 decimal points.  1 digit more granular than milliseconds, whatever that's called (trivia!).

-alex





Alex Mills

unread,
Sep 23, 2020, 2:42:56 PM9/23/20
to golang-nuts
My guess, is that a starting place would be something like:

var s = time.Now().UTC().String()[0:24]

an example of which looks like:

"2020-09-23 18:41:43.1568"

so I guess I just to know if there is a reliable way to parse that string back into a date using multiple programming languages.



Marcin Romaszewicz

unread,
Sep 23, 2020, 2:49:21 PM9/23/20
to Alex Mills, golang-nuts

Here's how to use it. I think this is exactly what you want:

--
You received this message because you are subscribed to the Google Groups "golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/golang-nuts/5aa0fbde-fc12-4e9a-a5bf-a8a1d8a76b76n%40googlegroups.com.
Reply all
Reply to author
Forward
0 new messages