Proper c# get timestamp


/ Published in: C#
Save to your folder(s)

Well, there is many faulty C# timestamp handling codes.

Here is a proper one, use UtcNow instead Now if you need UTC timestamp...


Copy this code and paste it in your HTML
  1. //Find unix timestamp (seconds since 01/01/1970)
  2. long ticks = DateTime.UtcNow.Ticks - DateTime.Parse("01/01/1970 00:00:00").Ticks;
  3. ticks /= 10000000; //Convert windows ticks to seconds
  4. timestamp = ticks.ToString();

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.