go - Understanding golang date formatting for time package -
so have function performing well.
func today()(result string){ current_time := time.now().local() result = current_time.format("01/02/2006") return }
prints mm/dd/yyyy
, thought more readable if had value greater 12 in days position make clear mm/dd/yyyy changed following
func today()(result string){ current_time := time.now().local() result = current_time.format("01/23/2004") return }
which chagrin caused bad results. prints mm/ddhh/dd0mm
realizing mistake see format defined reference time...
mon jan 2 15:04:05 -0700 mst 2006
i'm wondering if there other instances moment being used formatting reference date times, , if reference moment has nickname (like null island)?
the values in date string not arbitrary. can't change 02
03
, expect work. date formatter looks specific values, , knows 1
means month, 2
means day of month, etc.
changing 01/02/2006
01/23/2004
changing human-readable form says first name: ______ last name: ______
1 says first name: ______ ice cream: ______
. can't expect know ice cream
should mean last name
.
the name
the name provided "reference time", here:
parse parses formatted string , returns time value represents. layout defines format showing how the reference time, defined be
mon jan 2 15:04:05 -0700 mst 2006
and here:
these predefined layouts use in time.format , time.parse. the reference time used in layouts specific time:
mon jan 2 15:04:05 mst 2006
which unix time 1136239445. since mst gmt-0700, the reference time can thought of as
01/02 03:04:05pm '06 -0700
to define own format, write down the reference time formatted way; see values of constants ansic, stampmicro or kitchen examples. model demonstrate reference time looks format , parse methods can apply same transformation general time value.
to specify you're talking go's reference time, i'd "go's reference time." or blatantly obvious, "go's time.parse reference time."
as aside, function can shortened:
func today() string { return time.now().local().format("01/02/2006") }
Comments
Post a Comment