I am looking to generate global UNIX Timestamp, which is same for all countries and regions. I have already make my hands dirty with UNIX Timestamp on the platform of .NET (C#.NET). But I have noticed in different countries actually not in countries in different Time Zones might be, this time stamp has been changed.
Is it possible to make same for all time zones or region or countires?
Thanks
A Unix timestamp is defined as the number of elapsed seconds since the Unix epoch, which was a single point in time - usually defined as midnight on January 1st 1970 UTC. So the timestamp is already global - and the simplest way to generate it is to use DateTime.UtcNow
to get the UTC time (unaffected by time zone), rather than DateTime.Now
which returns the system's local time (which depends on the time zone).
private static readonly DateTime UnixEpoch =
new DateTime(1970, 1, 1, 0, 0, 0, DateTimeKind.Utc);
public long GetUnixTimestamp()
{
TimeSpan diff = DateTime.UtcNow - UnixEpoch;
return (long) diff.TotalSeconds;
}
See more on this question at Stackoverflow