minutes, hour, week ago

Run Settings
LanguageGo
Language Version
Run Command
package main import ( "fmt" "time" ) func main() { // Calculate the duration since the current time now := time.Now() duration := now.Sub(time.Date(2022, 12, 22, 21, 30, 0, 0, time.UTC)) // Convert the duration to human-readable form if duration < time.Minute { fmt.Println("Just now") } else if duration < time.Hour { fmt.Printf("%d minutes ago\n", int(duration.Minutes())) } else if duration < 24*time.Hour { fmt.Printf("%d hours ago\n", int(duration.Hours())) } else if duration < 7*24*time.Hour { fmt.Printf("%d days ago\n", int(duration.Hours()/24)) } else if duration < 30*24*time.Hour { fmt.Printf("%d weeks ago\n", int(duration.Hours()/24/7)) } else { fmt.Printf("%d months ago\n", int(duration.Hours()/24/30)) } }
Editor Settings
Theme
Key bindings
Full width
Lines