Time
Time goes on, and you are becoming a pro
Last updated
Was this helpful?
Time goes on, and you are becoming a pro
Last updated
Was this helpful?
Time in general uses Golang's time package library > and also this although slightly different syntax all applies here > .
Field
Description
.DiscordEpoch
Gives you Discord Epoch time in time.Time. {{.DiscordEpoch.Unix}}
would return in seconds > 1420070400.
.UnixEpoch
Gives you Unix Epoch time in time.Time.
.TimeHour
Variable of time.Duration type and returns 1 hour > 1h0m0s
.
.TimeMinute
Variable of time.Duration type and returns 1 minute > 1m0s
.
.TimeSecond
Variable of time.Duration type and returns 1 second > 1s
.
Function
Description
currentTime
Gets the current time, value is of type time.Time which can be used in a custom embed.
formatTime Time "arg"
Outputs given time in RFC822 formatting, first argument Time
shows it needs to be of type time.Time, also with extra layout if second argument is given - e.g. {{formatTime currentUserCreated "3:04PM"}}
would output 11:22AM
if that would have been user's creating time.
humanizeDurationHours
humanizeDurationMinutes
Sames as humanizeDurationHours
, this time duration is returned in minutes - e.g. {{humanizeDurationMinutes 3500000000000}}
would return 58 minutes
.
humanizeDurationSeconds
Sames as both humanize functions above, this time duration is returned in seconds - e.g. {{humanizeDurationSeconds 3500000000000}}
would return 58 minutes and 20 seconds
.
humanizeTimeSinceDays
Returns time passed since given argument of type time.Time in human readable format - e.g. {{humanizeTimeSinceDays currentUserCreated}}
newDate year month day hour minute second [timezone]
To demonstrate humanizeDurationHours
and also how to parse a timestamp, output will be like whois
command shows user's join server age.
{{humanizeDurationHours (currentTime.Sub .Member.JoinedAt.Parse)}}
To demonstrate newDate
to get Epoch times.
{{$unixEpoch := newDate 1970 1 1 0 0 0}} in seconds > {{$unixEpoch.Unix}}
{{$discordEpoch := newDate 2015 1 1 0 0 0}} in seconds > {{$discordEpoch.Unix}}
The currentTime
template is very extensive and can be used for displaying the current time, for different time zones, or in embeds in the "timestamp" field.
Returns given integer (whole number) or time.Duration argument in nanoseconds in human readable format - as how long it would take to get towards given time - e.g. {{humanizeDurationHours 9000000000000000000}}
returns 285 years 20 weeks 6 days and 16 hours
. More in .
Returns new type time.Time object in UTC using given syntax (all arguments need to be of type int), for example > {{humanizeDurationHours ((newDate 2059 1 2 12 34 56).Sub currentTime)}}
will give you how much time till year 2059 January 2nd 12:34:56. More examples in .
timezone
is an optional string argument which uses golang's function and For example: {{newDate 2020 4 20 12 34 56 "Atlantic/Reykjavik"}}
would return that time in GMT+0.
even more in depth here >