File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Beginning Java and the fly likes Date function Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Date function" Watch "Date function" New topic

Date function

Vasudevan Gopalan
Ranch Hand

Joined: Aug 29, 2003
Posts: 67
Can any one have useful functions like dateadd,datediff,trim ?

Bear Bibeault
Author and ninkuma

Joined: Jan 10, 2002
Posts: 63852

I really have no idea what you are asking about, but I'm assuming it is regarding date manipulation. As such, moving to Java in General (Beginner).

[Asking smart questions] [About Bear] [Books by Bear]
Balaji Balasubramaniam

Joined: Oct 09, 2003
Posts: 3
Look at java.util.Date class. It may be useful to you.

--Balaji<br />SCJP1.4,SCWCD,SCBCD
Joel McNary

Joined: Aug 20, 2001
Posts: 1824

The com.javaranch.common package has a JDate (That's Julian Date, I believe...) class that tracks a date as an integer -- very useful for date arithmetic.
Although there don't seem to be methods for converting to/from java.util.Date objects...feel free to try to implement those.

Piscis Babelis est parvus, flavus, et hiridicus, et est probabiliter insolitissima raritas in toto mundo.
Peter Kleczka

Joined: Feb 09, 2003
Posts: 18
Use GregorianCalendar. E.G. use its add() method to implement your dateadd functionality. Use Calendar's getTimeInMillis() to convert two dates, do the subtraction for diff and then use setTimeInMills() to get your diff date result.
Hope this helps.
Originally posted by Vasudevan Gopalan:
Can any one have useful functions like dateadd,datediff,trim ?

zhu a ming

Joined: Oct 05, 2003
Posts: 9

=======================<br />s=(LinkNode *)malloc(sizeof(ListNode));<br /> s->date=ch;<br /> s->next=head;<br /> head=s;<br /> ch=getchar();
Simon Pearce

Joined: Jul 22, 2003
Posts: 4
I must confess I've always found the whole Java Date area totally confusing. They have tried to build a multilingual data system, but the result is a mess.

I know this doesn't help you ... but I just feel cross about it.
So be warned - you WILL get confused!
On the other hand, maybe you could read up about it, come up with a brilliantly simple replacement, and make all our lives better.
Go for it!
Jerome Lumpkin

Joined: Aug 28, 2001
Posts: 10
Just don't forget about that annoying feature in GregorianCalendar, wherin the months are relative to 0 and not 1.
Jerome A. Lumpkin
Colin Pace

Joined: Sep 25, 2003
Posts: 9
you can read an excellent article on using java dates:

Colin Pace
Lisa D'Aniello
Ranch Hand

Joined: Sep 25, 2003
Posts: 42
Hi Vasu! You come from the fantastic world of Visual Basic, eh? Me too. I also have a difficult time with the date manipulation (and haven't quite gotten around to figuring it out), but I might be able to help with Trim().
I do not have exact syntax, but I think you should be able to use stringVariable.replace(' ',''). This should remove all spaces in the string.
If you want the same functionality as Trim() you could do a substring like this: stringVariable = stringVariable.substring(1,stringVariable.length - 1). So if stringVariable = " Hello " then it should say "Hello" after the substring has executed.
Best of luck,
Lisa M.
Pradeep bhatt
Ranch Hand

Joined: Feb 27, 2002
Posts: 8927

I feel that java Date classes were not designed properly. In fact there was a request for new Java Date classes bu Sun rejected it.

Pradeep bhatt
Ranch Hand

Joined: Feb 27, 2002
Posts: 8927

Here is link to java date discussion
Dirk Schreckmann

Joined: Dec 10, 2001
Posts: 7023
Thanks for the good link Pradeep.
Welcome to JavaRanch!
We ain't got many rules 'round these parts, but we do got one. Please change your display name to comply with The JavaRanch Naming Policy.
Thanks Pardner! Hope to see you 'round the Ranch!

[How To Ask Good Questions] [JavaRanch FAQ Wiki] [JavaRanch Radio]
I agree. Here's the link:
subject: Date function
It's not a secret anymore!