Discussion Locked
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 bfilmfan
Free code for that function at http://www.javascriptkit.com/script/script2/servertime.shtml
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") ;
or for a 24 hour clock use HOUR_OF_DAY instead of HOUR and throw away the AM/PM line.
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());
by ganaparthi
try using java.text.SimpleDateFormat to extract only time part.
This discussion is closed to new replies.
Trending Web Development posts
Sort by Trending
1 helpful
9 replies
Question Unanswered
Windows and macOS computers becoming slow or unstable after updates - what should I check first
0 helpful
0 replies
0 helpful
3 replies
Discussion
Optimizing WordPress widgets and DOM size
0 helpful
3 replies
Discussion Locked
Best Ways to Improve Website Visibility
0 helpful
5 replies