How to convert DateTime to DateTimeFormatter in Java

1 Answer

0 votes
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
 
public class ConvertDateTimeToDateTimeFormatter_Java {
    public static void main(String[] args) {
        LocalDateTime today = LocalDateTime.now();
         
        DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
 
        System.out.println(today.format(formatter));
    }
}
   
   
   
/*
run:
   
2024-08-12 08:02:20
   
*/

 



answered Aug 12, 2024 by avibootz
edited Aug 12, 2024 by avibootz

Related questions

1 answer 213 views
1 answer 184 views
1 answer 188 views
188 views asked Aug 12, 2024 by avibootz
1 answer 240 views
1 answer 272 views
1 answer 196 views
196 views asked Aug 12, 2024 by avibootz
1 answer 191 views
...