+ 1

How to display current day and time

using functions in java

23rd Apr 2017, 4:29 PM
sai Kumar
sai Kumar - avatar
3 odpowiedzi
+ 1
import java.text.SimpleDateFormat; import java.util.Date; public class Main{ public static void main(String[] app){ SimpleDateFormat date = new SimpleDateFormat("dd/MM/yyyy mm:HH:ss a"); System.out.println(date.format(new Date())); } }
23rd Apr 2017, 4:32 PM
Raj Sharma
+ 1
You can also use the java time like this: import java.time.LocalDateTime; public class Program { public static void main(String[] args) { LocalDateTime date= LocalDateTime.now() ; System.out.println(date); } }
24th Apr 2017, 9:46 AM
T0nd3
0
@sai reddy, this return the date and time of the server. So, for SoloLearn Playground the response for code may be different from your local date and time.
23rd Apr 2017, 4:35 PM
Raj Sharma