aspose file tools*
The moose likes Java in General and the fly likes Date milliseconds Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Java » Java in General
Bookmark "Date milliseconds" Watch "Date milliseconds" New topic
Author

Date milliseconds

Punya Pratap Singh
Ranch Hand

Joined: Nov 23, 2010
Posts: 80
long time = System.currentTimeMillis();
SimpleDateFormat sdf = new SimpleDateFormat("MMM dd,yyyy HH:mm:ss:ms");

java.util.Date resultdate = new java.util.Date(time);
//java.util.Date resultdate1 = sdf.format(time); //returns String I want Date.
// java.util.Date resultdate = sdf.parse(Long.toString(time)); //gives Exception
System.out.println(sdf.format(resultdate));

Prints--Jan 11,2011 11:54:40:5440

I am confused that 999 is the max value for millisecond and value greter than this converts into seconds,then why is it showing 5440 ?

also I want to format "resultdate" into Date again. convering long to String and then formatting It ,is giving format exception
Christophe Verré
Sheriff

Joined: Nov 24, 2005
Posts: 14687
    
  16

What is "ms" in SimpleDateFormat ?


[My Blog]
All roads lead to JavaRanch
Punya Pratap Singh
Ranch Hand

Joined: Nov 23, 2010
Posts: 80
milliseconds.
Christophe Verré
Sheriff

Joined: Nov 24, 2005
Posts: 14687
    
  16

Really ? Did you have a look at the API ? Do you see "ms" anywhere ?
Punya Pratap Singh
Ranch Hand

Joined: Nov 23, 2010
Posts: 80
Sorry Christophe .Its "S"
Christophe Verré
Sheriff

Joined: Nov 24, 2005
Posts: 14687
    
  16

Yes. "SSS" should solve your problem
Punya Pratap Singh
Ranch Hand

Joined: Nov 23, 2010
Posts: 80
Thanks a lot Christophe
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19538
    
  16

"ms" is nothing more than minutes followed by seconds - 54 followed by 40, combining into 5440.


SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6
How To Ask Questions How To Answer Questions
Punya Pratap Singh
Ranch Hand

Joined: Nov 23, 2010
Posts: 80
Yes, Rob Thanks.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Date milliseconds
 
Similar Threads
System Time with Milliseconds
Problem in Coverting one Date Format to Other date Format
integer number too large
org.hibernate.exception.GenericJDBCException: could not insert:
date inserting