wood burning stoves 2.0*
The moose likes Beginning Java and the fly likes java.util.Date Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of OCM Java EE 6 Enterprise Architect Exam Guide this week in the OCMJEA forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "java.util.Date" Watch "java.util.Date" New topic
Author

java.util.Date

akhter wahab
Ranch Hand

Joined: Mar 02, 2009
Posts: 151

i have date input like

want to attain this information with this date time formate..



can any body explain

Start Earning Online||Start Earning Using Java
Henry Wong
author
Sheriff

Joined: Sep 28, 2004
Posts: 18765
    
  40

Take a look at the SimpleDateFormat class. It can parse a string from your input format to a Date object, and then format a string out from that Date object.

Henry


Books: Java Threads, 3rd Edition, Jini in a Nutshell, and Java Gems (contributor)
akhter wahab
Ranch Hand

Joined: Mar 02, 2009
Posts: 151



i did this what i have to do for finding this Difference 77:17:14 Difference in Days 3.2
and its output is

why its 10/21/2010 ?? it should 10/20/2010
akhter wahab
Ranch Hand

Joined: Mar 02, 2009
Posts: 151

i use this


its output is Days Between Thu Oct 21 00:50:11 PKST 2010 and Mon Nov 08 19:06:04 PKT 2010 is 18

but still its not fullfiling my requirment of Difference in Days 3.2

and still now can't found any way for Difference 77:17:14 this
akhter wahab
Ranch Hand

Joined: Mar 02, 2009
Posts: 151

any help
Sridhar Santhanakrishnan
Ranch Hand

Joined: Mar 20, 2007
Posts: 317
akhter wahab wrote:why its 10/21/2010 ?? it should 10/20/2010


The string date is actually 5 hours behind GMT and your current time zone seems to be in Pakistan which is +5/+6 hours ahead of GMT. Hence the difference.
akhter wahab wrote:
its output is Days Between Thu Oct 21 00:50:11 PKST 2010 and Mon Nov 08 19:06:04 PKT 2010 is 18

but still its not fullfiling my requirment of Difference in Days 3.2


The sample dates that you are using here are different from the ones in your original post. The difference looks to be ok. Try using

(float)(24 * 3600 * 1000)
to get more precise values.


akhter wahab
Ranch Hand

Joined: Mar 02, 2009
Posts: 151

Sridhar Santhanakrishnan wrote:
akhter wahab wrote:why its 10/21/2010 ?? it should 10/20/2010


The string date is actually 5 hours behind GMT and your current time zone seems to be in Pakistan which is +5/+6 hours ahead of GMT. Hence the difference.
akhter wahab wrote:
its output is Days Between Thu Oct 21 00:50:11 PKST 2010 and Mon Nov 08 19:06:04 PKT 2010 is 18

but still its not fullfiling my requirment of Difference in Days 3.2


The sample dates that you are using here are different from the ones in your original post. The difference looks to be ok. Try using

(float)(24 * 3600 * 1000)
to get more precise values.




thanks it really helps me allot

and still now can't found any way for Difference 77:17:14
Sridhar Santhanakrishnan
Ranch Hand

Joined: Mar 20, 2007
Posts: 317
c2.getTime().getTime() - c1.getTime().getTime()


1) This gives the time in millis.
2) divide by 1000 to get the total number of seconds.
3) divide the resulting number by 3600 to get the hours.
4) divide the remainder by 60 to get the minutes.
5) the remainder, now should be the seconds.
try using the modulo operator.
 
Don't get me started about those stupid light bulbs.
 
subject: java.util.Date