How to convert java.util.Date to String in Java

1 Answer

0 votes
import java.text.SimpleDateFormat;
import java.util.Date;

public class MyClass {
    public static void main(String args[]) {
        Date date = new Date();

        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");

        String str = sdf.format(date);

        System.out.println(str);
    }
}



/*
run:

2023-11-27 09:56:43

*/

 



answered Nov 27, 2023 by avibootz

Related questions

1 answer 84 views
1 answer 78 views
1 answer 152 views
1 answer 111 views
1 answer 108 views
5 answers 292 views
292 views asked Nov 17, 2021 by avibootz
...