Reputation: 27
i have program that read from serial port and write them into text but i need time of data that come into my PC i cant adding time in front of the data
FileStream fileStream = new FileStream(filename, FileMode.Append);
var data = System.Text.Encoding.UTF8.GetBytes(temp);
// int time;
// time =Convert.ToInt32( DateTime.Today);
// MessageBox.Show(time.ToString());
fileStream.Write(data+//code?? , 0, data.Length);
fileStream.Close();
}
Upvotes: 0
Views: 641
Reputation: 7517
Assuming temp
is of type String.
Add DateTime.Now
before you convert the temp-Variable to a ByteArray.
Change this line...
var data = System.Text.Encoding.UTF8.GetBytes(temp);
to...
var data = System.Text.Encoding.UTF8.GetBytes(String.Format("{0} {1}",temp, DateTime.Now));
or to just get the time of day...
var data = System.Text.Encoding.UTF8.GetBytes(String.Format("{0} {1}",temp, DateTime.Now.ToString("T")));
Upvotes: 1