Print time format difference but reflect shows same

Disclaimer:
I apologize, I am new. >.<

Sample:
https://play.golang.org/p/qjXY1U6IMEh

Expectation:
All 6 (reflect.TypeOf) printed the same, but there are 4 different looking dates. I figured there would be at least 4 different types printed.

Question:
Is there another way or package that can clearly identify various Date/Time formatting from a String?

Other Thoughts:
Shouldn’t the type print as ‘String’ instead of ‘time.Time’

Hi, @Gabriel_Marquez, I’m getting different output for each line:


t Default Layout: 2009-11-10 23:00:00 +0000 UTC m=+0.000000001
time.Time

n Default Layout: 2020-02-10 09:10:10.01001001 +0000 UTC
time.Time

t US Layout: November 10, 2009
time.Time

n US Layout: February 10, 2020
time.Time

t ISO Layout: 2009-11-10
time.Time

n ISO Layout: 2020-02-10
time.Time

Program exited.


What are you getting?

I’m referring to ‘time.Time’ is all the same even though there are different looking dates.

That’s because you’re writing: reflect.TypeOf(then).String(). reflect.TypeOf gets you a “type” object (like System.Type in .NET or java.lang.Class in Java (I think; I don’t really know Java)). Then you call String on that type object and get the name of the type.

Is there a function that prints out the constant name that a string matches for me to check if its a date?

Like if had a string that said ‘Mon Jan _2 15:04:05 2006’ could it tell me the type is ‘ANSIC’ without me building some sort of switch myself?

https://golang.org/pkg/time/

Does a package exist that you know of that would tell me things like ‘layoutUS’ or ‘layoutISO’ just from looking at a string?

I don’t think there’s any way to do that with the standard library.

I’m curious: What project are you working on where you need to know the way a time is formatted?

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.