Computer scienceProgramming languagesGolangPackages and modulesStandard libraryTime package

Parsing and formatting time

Pinky and Brain

Report a typo

Help Pinky and Brain to find out what time it is now with a Go program! Your program takes as an input a date and time string in the format: year/month/dayThour:minute.

After parsing the date and time string, your program should do the following:

  • If it's not a weekend day and the time is the Evening (18:00 or later) print the message: "Try to take over the world!".

  • If the time is before the Evening print: "We have to wait for the evening, Pinky!".

  • If it's Saturday or Sunday, print: "Try asking me on Monday, Pinky".

Sample Input 1:

2006/01/02T15:04

Sample Output 1:

We have to wait for the evening, Pinky!
Write a program in Go
package main

import (
"fmt"
"time"
"log"
)

const (
DateLayout = "2006/01/02T15:04"
Evening = 18
)

func main() {
var dateString string
fmt.Scan(&dateString)

date, err := time.Parse(DateLayout, ?)
if err != nil {
log.Fatal(err)
}

dayOfWeek := ?.Weekday()
hour := date.?()

if ? == time.Saturday || dayOfWeek == time.? {
fmt.Println("Try asking me on Monday, Pinky")
} else {
if hour ? Evening {
fmt.Println("Try to take over the world!")
} else {
fmt.Println("We have to wait for the evening, Pinky!")
}
}
}
___

Create a free account to access the full topic