R, 97 95 93 Bytes
Menggunakan metode yang ditemukan di atas dalam R
c("Zzz","Good morning","Good afternoon","Good evening")[as.POSIXlt(Sys.time(),"G")$h%%20/6+1]
Penjelasan:
c("Zzz","Good morning","Good afternoon","Good evening") # Creates a vector with the greetings
[ # Open bracket. The number in the bracket will extract the corresponding greeting from the vector below
as.POSIXlt( # as.POSIXlt converts the object to one of the two classes used to represent date/times
Sys.time(), # Retrieves the current time on the OS
"G") # Converts the time to the desired time zone. Does output a warning, but still converts properly to GMT
$h # Extracts the hour from the object created by as.POSIXlt
%%20/6 # Methodology as used by other golfers
+1] # Vectors in R start from 1, and not 0 like in other languages, so adding 1 to the value ensures values range from 1 to 4, not 0 to 3
Contoh
Perhatikan bagaimana baris kode ini, tanpa menambahkan 1, adalah 10 elemen pendek
c('Zzz','Good morning','Good afternoon','Good evening')[0:23%%20/6]
[1] "Zzz" "Zzz" "Zzz" "Zzz" "Zzz" "Zzz"
[7] "Good morning" "Good morning" "Good morning" "Good morning" "Good morning" "Good morning"
[13] "Good afternoon" "Good afternoon"
Menambahkan 1 memastikan bahwa hasil yang diperoleh lebih besar dari 0
c('Zzz','Good morning','Good afternoon','Good evening')[as.integer(0:23)%%20/6+1]
[1] "Zzz" "Zzz" "Zzz" "Zzz" "Zzz" "Zzz"
[7] "Good morning" "Good morning" "Good morning" "Good morning" "Good morning" "Good morning"
[13] "Good afternoon" "Good afternoon" "Good afternoon" "Good afternoon" "Good afternoon" "Good afternoon"
[19] "Good evening" "Good evening" "Zzz" "Zzz" "Zzz" "Zzz"