0
I want to create a variable in my c# app, of type DateTime, that stores the current date and time?
I have a FileWriteAllText method, and I want to add the date and time to my file of type "bat"!
2 odpowiedzi
+ 4
Here is a way to do it:
// Get current date and time and convert it to a string
string str = "" + DateTime.Now;
// Print it in a file
File.WriteAllText("test.bat", str);
// Read the file and print its content to be sure it has been done
Console.WriteLine(File.ReadAllText("test.bat"));
If you want to use a DateTime object to format a file name have a look at this code:
https://code.sololearn.com/ch9VB2H81NPd/#cs
Hope this help.
0
I used this code:
//Formats the like this
//FILE_NAME = the string at the begining of the file
//{0:yyMMdd} = data format used from user input
//.bat = file extension
//usertext = variable used to store the user input
var data = string.Format("FILE_NAME_{0:yyMMdd}_END.bat", usertext);