By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
429,262 Members | 2,664 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 429,262 IT Pros & Developers. It's quick & easy.

Creating Report Date

P: n/a
We have a program which is used to upload data to our website.
A report file is saved each time and is supposed to reflect the date!
Not being a java programmer I think the following code is used to create the
report name.

try { copy("C:\\MDSPROXY\\REPORT\\eventLog.txt", "C:\\MDSPROXY\\REPORT\\"+
new java.util.Date().getYear() + new java.util.Date().getMonth() + new
java.util.Date().getDay() + new java.util.Date().getHours() + new
java.util.Date().getMinutes() +".txt"); }

Basically it doesn't work and every now and then creates a file name which
has already been used and so we get an overwrite request!

For example, a report finishing at 30/07/2004 17:42 is 104651742.txt
For 26/07/2004 18:07 it is 10461187.txt

Not sure if this is relevant but the short date format in W2000 control
panel is dd/MM/yyyy and the long date is dd MMMM yyyy

Netbeans IDE 3.4 was used to create the program.

Any advice would be gratefully received even pointing me to the correct java
forum; there does seem to be a lot of them!

Regards
Chris Curtis
Jul 17 '05 #1
Share this Question
Share on Google+
2 Replies


P: n/a
Chris Curtis wrote:
We have a program which is used to upload data to our website.
A report file is saved each time and is supposed to reflect the date!
Not being a java programmer I think the following code is used to create the
report name.

try { copy("C:\\MDSPROXY\\REPORT\\eventLog.txt", "C:\\MDSPROXY\\REPORT\\"+
new java.util.Date().getYear() + new java.util.Date().getMonth() + new
java.util.Date().getDay() + new java.util.Date().getHours() + new
java.util.Date().getMinutes() +".txt"); }

Basically it doesn't work and every now and then creates a file name which
has already been used and so we get an overwrite request!

For example, a report finishing at 30/07/2004 17:42 is 104651742.txt
For 26/07/2004 18:07 it is 10461187.txt

Not sure if this is relevant but the short date format in W2000 control
panel is dd/MM/yyyy and the long date is dd MMMM yyyy

Netbeans IDE 3.4 was used to create the program.

Any advice would be gratefully received even pointing me to the correct java
forum; there does seem to be a lot of them!


Chris,

I would suggest using java.text.SimpleDateFormat to create a String
representation of the date. Problems with your current implementation
include the following:

1) Date.getYear() returns (year - 1900)
2) The months and days are not 0-padded. So Feb. 11 and Dec. 1 both
produce "111" for Date.getMonth() + Date.getDate()
3) Date.getDay() returns the day of the week, not the day of the month.

You might also want to use File.separator in place of "\\" for portability.

HTH,
Ray

--
XML is the programmer's duct tape.
Jul 17 '05 #2

P: n/a
Thanks for your time Ray.
Well that explains the problem!
As for implementing the solution I need to find me a java man!

Regards
Chris Curtis

"Raymond DeCampo" <rd******@spam.twcny.spam.rr.spam.com.spam> wrote in
message news:Li*******************@twister.nyroc.rr.com...
Chris Curtis wrote:
We have a program which is used to upload data to our website.
A report file is saved each time and is supposed to reflect the date!
Not being a java programmer I think the following code is used to create the report name.

try { copy("C:\\MDSPROXY\\REPORT\\eventLog.txt", "C:\\MDSPROXY\\REPORT\\"+ new java.util.Date().getYear() + new java.util.Date().getMonth() + new
java.util.Date().getDay() + new java.util.Date().getHours() + new
java.util.Date().getMinutes() +".txt"); }

Basically it doesn't work and every now and then creates a file name which has already been used and so we get an overwrite request!

For example, a report finishing at 30/07/2004 17:42 is 104651742.txt
For 26/07/2004 18:07 it is 10461187.txt

Not sure if this is relevant but the short date format in W2000 control
panel is dd/MM/yyyy and the long date is dd MMMM yyyy

Netbeans IDE 3.4 was used to create the program.

Any advice would be gratefully received even pointing me to the correct java forum; there does seem to be a lot of them!

Chris,

I would suggest using java.text.SimpleDateFormat to create a String
representation of the date. Problems with your current implementation
include the following:

1) Date.getYear() returns (year - 1900)
2) The months and days are not 0-padded. So Feb. 11 and Dec. 1 both
produce "111" for Date.getMonth() + Date.getDate()
3) Date.getDay() returns the day of the week, not the day of the month.

You might also want to use File.separator in place of "\\" for

portability.
HTH,
Ray

--
XML is the programmer's duct tape.

Jul 17 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.