0 0
Read Time:42 Second

Write a Java program to display combine local date and time in a single object

import java.time.LocalDate;
import java.time.LocalDateTime;
import java.time.LocalTime;
import java.time.format.DateTimeFormatter;

class Combine_Local_DateTime
{
    public static void main(String[] args)
	{                       
        LocalDate local_d = LocalDate.now();
        String ld = local_d.format(DateTimeFormatter.ofPattern("yyyy-MMM-dd"));
        System.out.println("Local Date = " + ld);        
        LocalTime local_t = LocalTime.now();
        String lt = local_t.format(DateTimeFormatter.ofPattern("hh:mm:ss a"));
        System.out.println("Local Time = " + lt);        
        LocalDateTime local_dt = LocalDateTime.of(local_d, local_t);        
        String ldt = local_dt.format(DateTimeFormatter.ofPattern("yyyy-MMM-dd hh:mm:ss a"));
        System.out.println("Combine Local Date Time = " + ldt);
    }    
}
/*
Local Date = 2022-Nov-05
Local Time = 12:47:05 PM
Combine Local Date Time = 2022-Nov-05 12:47:05 PM
*/
Happy
Happy
0 %
Sad
Sad
0 %
Excited
Excited
0 %
Sleepy
Sleepy
0 %
Angry
Angry
0 %
Surprise
Surprise
0 %
Verified by MonsterInsights