Ad
Fundamentals
Strings

Using go time package

Code
Diff
  • package kata
    
    import (
      "fmt"
      "time"
    )
    
    // MinsToHours converts Minutes to Hours and Minutes
    func MinsToHours(mins int) string {
      duration := time.Duration(mins) * time.Minute
      
      hour := int(duration.Seconds() / 3600)
      minute := int(duration.Seconds() / 60) % 60
      
      return fmt.Sprintf("%d:%02d", hour, minute)
    }
    
    
    • package kata
    • import "fmt"
    • import (
    • "fmt"
    • "time"
    • )
    • // MinsToHours converts Minutes to Hours and Minutes
    • func MinsToHours(mins int) string {
    • return fmt.Sprintf("%d:%.2d", mins / 60, mins % 60)
    • }
    • duration := time.Duration(mins) * time.Minute
    • hour := int(duration.Seconds() / 3600)
    • minute := int(duration.Seconds() / 60) % 60
    • return fmt.Sprintf("%d:%02d", hour, minute)
    • }