Discussion Locked

java programming - time

0 helpful
5 replies
Closed to new repliesThis discussion is closed. It stays readable, but it takes no new replies.
Hey does anybody know a simple way to call and display the system time from the pc using java code? I have to submit an assignment and part of it involves displaying the system time on a simple java program - i was able to track down one method in 'java.util.Date' but this displays both the date AND the time...any help?

5 replies

by martin simons

GregorianCalendar a = new GregorianCalendar( ) ;
System.out.println(a.get(Calendar.HOUR) + ":" +
( (a.get(Calendar.MINUTE) < 10) ? "0" : "") +
a.get(Calendar.MINUTE) +
( (a.get(Calendar.AM_PM) == Calendar.AM) ? "AM" : "PM") ;

by martin simons

SimpleDateFormat sdf = new SimpleDateFormat("hh:mm a") ;
System.out.println(sdf.format(new Date());

SimpleDateFormat sdf2 = new SimpleDateFormat("HH:mm") ;
System.out.println(sdf.format(new Date());

This discussion is closed to new replies.