Evyatar
Evyatar

Reputation: 1157

Add one hour to summer dst

I have the follow code to get the local time in ms:

var dtNow = DateTime.Now;
var time = TimeSpan.FromMilliseconds((dtNow - new DateTime(1970, 1, 1, 0, 0, 0, DateTimeKind.Utc).ToLocalTime()).TotalMilliseconds);
long end_time = Convert.ToInt64(time.TotalMilliseconds);

The time object indicate to correct hour (11:20:00) but the ms object indicate on 12:20:00, Why its happend and how i can fix it?

Before the summer dst Its works perfecr.

Thanks!

Upvotes: 0

Views: 70

Answers (1)

Jeroen van Langen
Jeroen van Langen

Reputation: 22073

Because your dtNow = DateTime.Now; is local and with (dtNow - new DateTime(1970, 1, 1, 0, 0, 0, DateTimeKind.Utc).ToLocalTime()) you're converting the time to local again .ToLocalTime()

Try:

var dtNow = DateTime.UtcNow;

Upvotes: 1

Related Questions