+ 4

How to make clock

can we make a program by which we can see current time in JAVA or C++

8th Jul 2017, 4:36 PM
Irwin Lopez
Irwin Lopez - avatar
4 Answers
+ 6
public class Program { import java.util.Date; import java.text.DateFormat; import java.text.SimpleDateFormat; import java.util.Calendar; public class GettingCurrentDate { public static void main(String[] args) { //getting current date and time using Date class DateFormat df = new SimpleDateFormat("dd/MM/yy HH:mm:ss"); Date dateobj = new Date(); System.out.println(df.format(dateobj)); /*getting current date time using calendar class * An Alternative of above*/ Calendar calobj = Calendar.getInstance(); System.out.println(df.format(calobj.getTime())); } } }
8th Jul 2017, 5:02 PM
John Joy Raj
John Joy Raj - avatar
+ 3
import java.util.Date; public class DateDemo { public static void main(String args[]) { // Instantiate a Date object Date date = new Date(); // display time and date using toString() System.out.println(date.toString()); } }
8th Jul 2017, 4:38 PM
John Joy Raj
John Joy Raj - avatar
+ 2
can you send me the program that I can run and see . in play ground.
8th Jul 2017, 4:40 PM
Irwin Lopez
Irwin Lopez - avatar
+ 1
if u want the seconds of the time to be counting. how will u write the code
17th Sep 2017, 3:22 PM
Michael Kupa