The Artima Developer Community
Sponsored Link

Java Answers Forum
Covert milliseconds to time/date

2 replies on 1 page. Most recent reply: Jun 8, 2004 8:47 AM by Joe Cheng

Welcome Guest
  Sign In

Go back to the topic listing  Back to Topic List Click to reply to this topic  Reply to this Topic Click to search messages in this forum  Search Forum Click for a threaded view of the topic  Threaded View   
Previous Topic   Next Topic
Flat View: This topic has 2 replies on 1 page
yinfang xu

Posts: 1
Nickname: yinfang
Registered: Jun, 2004

Covert milliseconds to time/date Posted: Jun 5, 2004 6:14 AM
Reply to this message Reply
Advertisement
My Code:

Date d = new Date();
System.out.println (d.getTime());

This code get the milliseconds (a long number) of the current time. For example: 1086440827929
I konw this long number contains informations that are more than hours, minuntes, and seconds.

Could anybody help me to convert this long number into a time/date format? Is there any method can do this converstion?

Thanks a lot!


Philip Foulkes

Posts: 19
Nickname: frodo
Registered: May, 2004

Re: Covert milliseconds to time/date Posted: Jun 5, 2004 3:11 PM
Reply to this message Reply
I would u a Calendar to solve this problem. You get the date in a similar way, just look at your API for all the other thing you can do.

Calendar cal = Calendar.getInstance();
		
		System.out.println (cal.get(Calendar.HOUR) + ":" + cal.get(Calendar.MINUTE) + ":" + cal.get(Calendar.SECOND));

Joe Cheng

Posts: 65
Nickname: jcheng
Registered: Oct, 2002

Re: Covert milliseconds to time/date Posted: Jun 8, 2004 8:47 AM
Reply to this message Reply
See the java.text.DateFormat class: http://java.sun.com/j2se/1.4.2/docs/api/java/text/DateFormat.html

Flat View: This topic has 2 replies on 1 page
Topic: help, need help for assignment Previous Topic   Next Topic Topic: Someone educate me...

Sponsored Links



Google
  Web Artima.com   

Copyright © 1996-2019 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use