How to convert DateTime to string in Java

1 Answer

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

 



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

Related questions

1 answer 184 views
1 answer 185 views
1 answer 196 views
196 views asked Aug 12, 2024 by avibootz
1 answer 191 views
1 answer 190 views
190 views asked Aug 12, 2024 by avibootz
2 answers 321 views
1 answer 222 views
...