Go Back   TechArena Community > Software > Software Development
Become a Member!
Forgot your username/password?
Register Tags Active Topics RSS Search Mark Forums Read SiteMap

Tags: , , , , , ,

Sponsored Links



BigDecimal and Date

Software Development


Reply
 
Thread Tools Search this Thread
  #1  
Old 07-02-2010
Member
 
Join Date: Dec 2009
Posts: 292
BigDecimal and Date

Hello,
I would like to display the month and year of a date in this format: 01/09. The fields "datdeb" in the database is of type BigDecimal. I formatted and got this, 01/70 even if I change the year, it is still 70. What is this can you please explain me. Any help on this will be highly appreciated. Thanks in advance.

Last edited by Miles Runner : 07-02-2010 at 02:16 AM.
Reply With Quote
  #2  
Old 07-02-2010
Member
 
Join Date: Nov 2009
Posts: 331
Re: BigDecimal and Date

Hi,
It would be nice if you explain that stores the field datdeb your database, why it is mapped to a BigDecimal and by what method you've formatted. Otherwise burns to doublet seen your results I suspect a problem with formatting of a misuse of Date.getTime that as stated in the javadoc
Code:
Returns the number of milliseconds since January 1, 1980, 00:00:00 GMT represented by this Date object.
Reply With Quote
  #3  
Old 07-02-2010
Member
 
Join Date: Dec 2009
Posts: 292
Re: BigDecimal and Date

Hello,
This is a part of my code, this part contains the logic of the program. Just have a look at it and if you find any mistake then please help me with that.
Code:
BigDecimal bgdec = new BigDecimal(tt.get(0).getDebExe().function toString() {
    [native code]
}());
Date dt = new Date(bgdec.longValue());
String rf = STRs.dttostring1(dt);
societeForm.setDatdeb(STRs);
Reply With Quote
  #4  
Old 07-02-2010
Member
 
Join Date: Nov 2009
Posts: 335
Re: BigDecimal and Date

Hello,
The Date constructor taking a long as parameter (the one you used), adds that many milliseconds to 01/01/1980. So you're with your method, 108 ms after the start of the day, which explains the result that you (and this is the sensed bp). The date that you start in the base (108) must be analyzed as a string, not a number. So you have no need to go through BigDecimal (which also serve to manipulate real numbers), or anything else. I understand how the date is stored, you should take the last two characters, convert them with Integer.parseInt () -> you'll have this year. Then you take what is left and with the same operation you get the month.
Reply With Quote
  #5  
Old 07-02-2010
Member
 
Join Date: Nov 2009
Posts: 447
Re: BigDecimal and Date

Hello,
The above mentioned is correct, I am with it. But the main point in my opinion, and if you want to move forward is to learn to read the javadoc and not wanting to copy what has been done in another language. Finally for you to see. So, I think you should have a look at the java application programming interface. It will be more helpful to you.
Reply With Quote
  #6  
Old 07-02-2010
Member
 
Join Date: Dec 2009
Posts: 292
Re: BigDecimal and Date

Hello,
I think I have found a solution for this now, this is what i do in my code now , and it works for well for now.
Code:
String dt ="23/10/2008";
String[] tb = dt.split("/");
String fmt = tb[2]+"/"+ Tab[1]+"/"+ Tab[0];
It's up to you to suit your needs
Reply With Quote
Reply

  TechArena Community > Software > Software Development


Thread Tools Search this Thread
Search this Thread:

Advanced Search


Similar Threads for: "BigDecimal and Date"
Thread Thread Starter Forum Replies Last Post
Baseline Column Date automatically updates Finish Date Adam 1980 Microsoft Project 3 18-05-2011 07:08 PM
Java BigDecimal to Integer Anthony12 Software Development 6 11-08-2010 06:09 PM
Lag time between Start-Date and Finish-Date Shahriar N k Microsoft Project 5 22-01-2009 09:42 PM
Dependent start date task with fixed end date horatio123 Microsoft Project 1 31-08-2008 08:59 AM
Changing start date and creating formula for finish date Lisa M Microsoft Project 2 11-09-2006 06:10 PM


All times are GMT +5.5. The time now is 07:47 AM.