dkim18
asked on
creating dir name with current date and time
hi!
i am trying to create dir and its name with current date and time that the user excute the application.
ex)if a user run application on 10.6.2004 at 06:23 pm
then file name shold be something like:
filename_10_06_2004_18_23
thanks,
i am trying to create dir and its name with current date and time that the user excute the application.
ex)if a user run application on 10.6.2004 at 06:23 pm
then file name shold be something like:
filename_10_06_2004_18_23
thanks,
This will do the job..
import java.io.File;
import java.util.Date;
public class temp {
public static void main(String args[]) {
Date dt = new Date();
String t = "file_"+dt.getDate()+"_"+d t.getMonth ()+"_"+dt. getYear()+ "_"+dt.get Hours()+"_ "+dt.getMi nutes();
File tempFile=new File(t);
if(tempFile.mkdir()) {
System.out.println("Direct ory Created");
}
}
}
:-)
import java.io.File;
import java.util.Date;
public class temp {
public static void main(String args[]) {
Date dt = new Date();
String t = "file_"+dt.getDate()+"_"+d
File tempFile=new File(t);
if(tempFile.mkdir()) {
System.out.println("Direct
}
}
}
:-)
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Yaa it is I just kept it like that........
If both above codes are mixed its done right.....
Anyway sorry for the depricated method answer
:-)
If both above codes are mixed its done right.....
Anyway sorry for the depricated method answer
:-)
ASKER
i applied the following to my program...
String t = "file_"+dt.getDate()+"_"+d
and got the following..
file_8_9_104_0_7
month and year seem to be wrong.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
If you really want to use the date scheme you outlined above, you can do this with the SimpleDateFormat class, for example :
SimpleDateFormat sdf = new SimpleDateFormat("MM_dd_yy
System.out.println("date = [" + sdf.format(new Date()) + "]");
The output would be :
date = [10_07_2004_17_54_35]
But beware - this strategy is only unique to the second... you could modify the above example to include milliseconds to, in the following way:
SimpleDateFormat sdf = new SimpleDateFormat("MM_dd_yy
System.out.println("date = [" + sdf.format(new Date()) + "]");
Then you'll end up with :
date = [10_07_2004_17_57_04_328]