Time
Time goes on, and you are becoming a pro
Time in general uses Golang's time package library > https://golang.org/pkg/time/#time and also this although slightly different syntax all applies here > https://gobyexample.com/time.
Field
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
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]
Example:
To demonstrate
humanizeDurationHours
and also how to parse a timestamp, output will be likewhois
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}}
More Info
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.
even more in depth here > https://golang.org/pkg/time/
Last updated
Was this helpful?