• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

java.util.Date

 
akhter wahab
Ranch Hand
Posts: 151
Java MyEclipse IDE Python
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
i have date input like

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



can any body explain
 
Henry Wong
author
Marshal
Pie
Posts: 21497
84
C++ Chrome Eclipse IDE Firefox Browser Java jQuery Linux VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
akhter wahab
Ranch Hand
Posts: 151
Java MyEclipse IDE Python
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator


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
Posts: 151
Java MyEclipse IDE Python
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 151
Java MyEclipse IDE Python
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
any help
 
Sridhar Santhanakrishnan
Ranch Hand
Posts: 317
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 151
Java MyEclipse IDE Python
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 317
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic