Created
September 12, 2022 03:19
-
-
Save jonathasborges1/098ee055ab33aa7b55650bbdbd73f8b1 to your computer and use it in GitHub Desktop.
Aula 04 - Java - Manipulação de string e datas
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.util.Locale; | |
import java.time.LocalDate; | |
import java.time.LocalDateTime; | |
import java.time.format.TextStyle; | |
public class Main { | |
public static void main(String[] args){ | |
String nome = "Jhon"; | |
LocalDate hoje = LocalDate.now(); | |
int agora = LocalDateTime.now().getHour(); | |
Locale brasil = new Locale("pt","BR"); | |
String diaSemana = hoje.getDayOfWeek().getDisplayName(TextStyle.FULL,brasil); | |
String saudacao = "default"; | |
if(agora >= 0 && agora < 12){ | |
saudacao = "bom dia"; | |
} | |
if(agora >= 12 && agora < 18){ | |
saudacao = "boa tarde"; | |
} | |
if(agora >= 18 && agora < 24){ | |
saudacao = "boa noite"; | |
} | |
// ISO 8601 | |
// LocalDate hoje = LocalDate.now(); | |
// System.out.println(hoje.getDayOfMonth()); | |
// System.out.println(hoje.getDayOfWeek()); | |
// System.out.println(hoje.getDayOfYear()); | |
System.out.printf("Olá, %s. Hoje é %s, %s.%n",nome,diaSemana,saudacao); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment