I wanted to calculate the time now with what I get from a string like this:
2016-04-16T15:55:53Z
But the time is three hours higher than our spindle, I wanted some output like:
Já se decorreu 0 horas, 0 minutos e 0 segundos...
I wanted to calculate the time now with what I get from a string like this:
2016-04-16T15:55:53Z
But the time is three hours higher than our spindle, I wanted some output like:
Já se decorreu 0 horas, 0 minutos e 0 segundos...
I'll answer what you give:
DateTime.Now - DateTime.Parse("2016-04-16T15:55:53Z")
If you're not sure that the text has this format, it's best to use TryParseExact()
.
As for the spindle depends on how you have this information, it needs to be somewhere. There are several ways to solve this, some more correct than others depending on the scenario.
To put the extended elapsed time I already answered another question .
static void Main(string[] args)
{
int hours, minutes, seconds;
DateTime dt1,dt2;
dt1 = Convert.ToDateTime("2016-04-16T15:55:53Z");
dt2 = DateTime.Now;
dt2.AddHours(3);
seconds = (int)dt2.Subtract(dt1).TotalSeconds % 60;
minutes = (int)dt2.Subtract(dt1).TotalMinutes % 60;
hours = (int)dt2.Subtract(dt1).TotalHours;
Console.WriteLine("Ja se passaram: " + hours + " hora(s), " + minutes + " minuto(s) e " + seconds + " segundo(s)");
Console.ReadKey();
}
Not the best solution but solved my question.