• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Date function

 
Vasudevan Gopalan
Ranch Hand
Posts: 67
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Can any one have useful functions like dateadd,datediff,trim ?

Regards
Vasu
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 65128
92
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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).
bear
 
Balaji Balasubramaniam
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Look at java.util.Date class. It may be useful to you.
 
Joel McNary
Bartender
Posts: 1840
Eclipse IDE Java Ruby
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Peter Kleczka
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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 ?

Regards
Vasu
 
zhu a ming
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
java.util.date
 
Simon Pearce
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
you can read an excellent article on using java dates:
http://www.javaworld.com/javaworld/jw-12-2000/jw-1229-dates.html

Colin Pace
 
Lisa D'Aniello
Ranch Hand
Posts: 42
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 8933
Firefox Browser Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 8933
Firefox Browser Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Here is link to java date discussion
http://www.javalobby.com/thread.jsp?forum=61&thread=4758
 
Dirk Schreckmann
Sheriff
Posts: 7023
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks for the good link Pradeep.
zhuam,
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!
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic