Date and Time conversion  
Author Message
Rizwan





PostPosted: 2005-1-28 0:30:00 Top

java-programmer, Date and Time conversion I have an Integer variable which contains date in YYYYMMDD format. I want to
convert it first to a Date variable and then to a String variable with
format MM/DD/YYYY. How can I do that?

I also have an Integer which contain time in HHMMSS format. I want to
convert it to a String variable with format HH:MM:SS. How can I do that?

TIA



 
klynn47





PostPosted: 2005-1-28 1:36:00 Top

java-programmer >> Date and Time conversion One thing I would suggest for the first one (I assume you mean it's
stored in an int variable), I would convert it to a String, and then
left pad with 0s to make sure you have four numbers at the beginning.
Then the year would be substring(0,4), then month would be
substring(4,6), and the day would be substring(6).

If the second form is stored in an int, you could do somethind like

seconds = time % 100
time = time/100
minutes = time % 100
hour = time/100
Then you could concatenate them

hour + ":" + minute + ":" + seconds