Skip to content

Instantly share code, notes, and snippets.

@Ankit-Slnk
Last active February 23, 2022 16:19
Show Gist options
  • Save Ankit-Slnk/648de1b6b980b1b565542e1eca612eda to your computer and use it in GitHub Desktop.
Save Ankit-Slnk/648de1b6b980b1b565542e1eca612eda to your computer and use it in GitHub Desktop.
public static String greeting() {
Calendar c = Calendar.getInstance();
int timeOfDay = c.get(Calendar.HOUR_OF_DAY);
if (timeOfDay >= 0 && timeOfDay < 12) {
return "Good Morning";
} else if (timeOfDay >= 12 && timeOfDay < 16) {
return "Good Afternoon";
} else if (timeOfDay >= 16 && timeOfDay < 21) {
return "Good Evening";
} else if (timeOfDay >= 21 && timeOfDay < 24) {
return "Good Night";
} else {
return "Hello";
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment