• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

getting System time

 
kavya krushi
Ranch Hand
Posts: 48
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Hi all,
Is there any way to get the systems time through a java program ?
I tried using the getProperties option but it just gives informations related to Zone ... I need to get the Systems time during which a program of mine is running ...
thanks
kavya
 
Jane Griscti
Ranch Hand
Posts: 3141
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Kayva,
You can get the current system time using <code>java.util.Date();</code>
Hope that helps.
------------------
Jane Griscti
Sun Certified Java 2 Programmer
"When ideas fail, words come in very handy" -- Goethe
 
Val Dra
Ranch Hand
Posts: 439
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I think it's best to use System class for this and get the time from the System. Using System.currentTimeMillis()
 
kavya krushi
Ranch Hand
Posts: 48
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Jane , val
Thanks alot for your responces ... I'd already tried both of these options ... I need to get the timing info in the actual format ( not just milliseconds) ... I tried the toString method but it does not seem to work ... is there any particular method
which prints the time/date in the actual format ???
thanks
kavya
 
Val Dra
Ranch Hand
Posts: 439
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Use SimpleDateFormat class to format the date to look how you like.
 
Art Metzer
Ranch Hand
Posts: 241
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi, Kavya. Here's some code to help you out:

See also this Sun link for more about customizing date and time formats using java.text.SimpleDateFormat.
Hope this helps,
Art
 
kavya krushi
Ranch Hand
Posts: 48
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Thanks Art...
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic