• Post Reply Bookmark Topic Watch Topic
  • New Topic

current time  RSS feed

 
aymane chetibi
Ranch Hand
Posts: 175
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello,

Is there a way I can get the current clock time including milliseconds in java???
the java.util.Date class inly gives you seconds.

Thank you for any help..

Regards,
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 66306
152
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Not an advanced question. Moved to the intermediate forum.
 
Keith Lynn
Ranch Hand
Posts: 2409
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yes, you can use the Calendar class. There is a method called get which you can send the int Calendar.MILLISECONDS to to get the millisecond that the object was created.
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 66306
152
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by aymane chetibi:

the java.util.Date class inly gives you seconds.


The very first sentence of the javadoc for java.util.Date says:

The class Date represents a specific instant in time, with millisecond precision.


Do you question it?
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 66306
152
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Keith Lynn:
Yes, you can use the Calendar class.


Calendar is a wrapper around java.util.Date.
 
Jeff Albertson
Ranch Hand
Posts: 1780
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hint: Look in System.
 
aymane chetibi
Ranch Hand
Posts: 175
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
thanks dude, I forgot about this class.

Regards,
 
aymane chetibi
Ranch Hand
Posts: 175
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
yea System returns the time in millisecond then you have to extract hours, min, ... .
What I want is a time like HH:MM:SS:mmm

,
 
aymane chetibi
Ranch Hand
Posts: 175
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Bear,

I agree that Date class specifies the time to the closest millisecond but I don't see any method that enables you to get the millisecond part of a time.

Regards,
 
Matti Poro
Ranch Hand
Posts: 41
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You can define a custom pattern in SimpleDateFormat. It inherits a method String format(Date date)
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!