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 216 views
1 answer 186 views
1 answer 191 views
191 views asked Aug 12, 2024 by avibootz
1 answer 245 views
1 answer 276 views
1 answer 200 views
200 views asked Aug 12, 2024 by avibootz
1 answer 195 views
...