I have same result 1338161400 when I do
DateTime origin = new DateTime(1970, 1, 1, 0, 0, 0, 0);
DateTime date = DateTime.Parse(@"28/05/12 01:30");
TimeSpan diff = date.ToUniversalTime() - origin;
Console.WriteLine( (Math.Floor(diff.TotalSeconds)).ToString());
as well as when I use date.AddHours(-4) :
DateTime origin = new DateTime(1970, 1, 1, 0, 0, 0, 0);
DateTime date = DateTime.Parse(@"28/05/12 01:30");
date.AddHours(-4);
TimeSpan diff = date.ToUniversalTime() - origin;
Console.WriteLine( (Math.Floor(diff.TotalSeconds)).ToString());
I try to get 1338168600 like http://www.mbari.org/staff/rich/utccalc.htm
Update:
Thanks I changed to
DateTime origin = new DateTime(1970, 1, 1, 0, 0, 0, 0);
DateTime date = DateTime.Parse(@"28/05/2012 01:30");
date = date.AddHours(-4);
date = date.ToUniversalTime();
TimeSpan diff = date - origin;
Console.WriteLine((Math.Floor(diff.TotalSeconds)).ToString());
But I got 1338147000 still not 1338168600
It tends to be between 0.5 and 15 milliseconds.
DateTime. Today is static readonly . So supposedly it should never change once (statically) instantiated.
The Now property returns a DateTime value that represents the current date and time on the local computer.
AddHours returns a new DateTime object which is the result of adding the hours onto the original. The original is left unchanged. Thus you want date = date.AddHours (-4); instead of just date.AddHours (-4); Show activity on this post.
AddHours returns a new DateTime object which is the result of adding the hours onto the original. The original is left unchanged. Thus you want date = date.AddHours (-4); instead of just date.AddHours (-4);
AddHours returns a new DateTime object which is the result of adding the hours onto the original. The original is left unchanged. Thus you want date = date.AddHours(-4); instead of just date.AddHours(-4); The original date is set 4 hours backward but you didn't set it to new date.
Returns a new DateTime that adds the specified number of minutes to the value of this instance. Gets the day of the week represented by this instance. Returns a new DateTime that adds the specified number of years to the value of this instance.
AddHours
returns a new DateTime
object which is the result of adding the hours onto the original. The original is left unchanged.
Thus you want date = date.AddHours(-4);
instead of just date.AddHours(-4);
Dates are immutable objects, i.e. they cannot be modified after creation. DateTime.AddHours returns a new DateTime instance which is shifted backwards by 4 hours but "date" will not be modified.
Use:
DateTime newDate = date.AddHours(-4);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With