Answer the question
In order to leave comments, you need to log in
How to convert unix to datetime c#?
Good afternoon, I want to make a graph with data, but I have time in unix, when I convert it, an error is generated. Here is my code:
// Пример: 44443.8340277778 это дни от 1900 года, я от них отнимаю 70 лет и в секунды
string[] lines = File.ReadAllLines(directory + @"\newData.dat");
for (int j = 0; j < lines.Length - 1; j += 4)
{
try
{
long unix = (long)TimeSpan.FromDays(long.Parse(lines[j]) - 2550).TotalSeconds;
DateTimeOffset dateTimeOffset = DateTimeOffset.FromUnixTimeSeconds(unix);
DateTime utc = dateTimeOffset.UtcDateTime;
dates.Add(utc.ToString("yyyy-MM-dd-HH-mm"));
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
}
chart1.AxisX.Clear();
chart1.AxisX.Add(new Axis()
{
Title = "Время",
Labels = dates
});
Answer the question
In order to leave comments, you need to log in
There is only one Parse in your block, and the error seems to be in it.
If the example is correct, then I see two errors:
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question