Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / General / May 2005

Tip: Looking for answers? Try searching our database.

Getting Date Difference in Java.

Thread view: 
Lucky - 06 May 2005 14:55 GMT
Hi
In oracle, if I need to get the sysdate, I would do some thing like this
   select sysdate from dual;
And if I need , the difference between sysdate and a specific date ,say
"pdate" ,I would do,
   select sysdate - pdate from dual
This would give me the difference in days ,so for ex
  select sysdate -to_date('01-JAN-2005') from dual
would give me 125 as the number of days.
---
Now what I want to know is that in java how do I this. I tried to play
around with the Date and Calendar objects.
These objects are giving me individual feilds like day,month and year etc,
but not date as a whole. So my question is

1. How do I get the date in java in a specific format (in any format I
choose). What is the best object for this.
2. How do I get the difference in 2 dates, which should give me in number of
days.

Your quick responses are appreciated.

Thanks,

PS. By the way how do we do the same in JavaScript.
Joseph Dionne - 06 May 2005 15:10 GMT
> Hi
> In oracle, if I need to get the sysdate, I would do some thing like this
[quoted text clipped - 21 lines]
>
> PS. By the way how do we do the same in JavaScript.

Look up DateForamt* classes, and date1.getTime() - date2.getTime() gives
you the delta.  Hope that helps.

joseph
Igor Kolomiyets - 06 May 2005 16:21 GMT
Difference date1.getTime() - date2.getTime() will be in milliseconds. To
get number of days divide it by 86400000L.

>> Hi
>> In oracle, if I need to get the sysdate, I would do some thing like this
[quoted text clipped - 28 lines]
>
> joseph
EricF - 07 May 2005 05:26 GMT
I suggest using the GregorianCalendar class to get the difference.

Eric

>Difference date1.getTime() - date2.getTime() will be in milliseconds. To
>get number of days divide it by 86400000L.
[quoted text clipped - 33 lines]
>>
>> joseph


Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.