Note that DateTimeOffset.ToUnixTimeSeconds
and DateTimeOffset.FromUnixTimeSeconds
exist as of .NET 4.6.
Consider using those instead.
If you really need a nullable, you can still wrap the framework methods in an extension method.
Also, generally generally you should be using DateTimeOffset instead of DateTime unless you explicitly want to ignore timezones (e.g. local noon regardless of timezone). (Somewhat debatable, see comments. Still, as long as you make sure you work in UTC then converting between DateTime
and DateTimeOffset
shouldn't be a problem for Unix time conversion - and certainly no more than it would be a problem with manual calculations.)
Note that DateTimeOffset.ToUnixTimeSeconds
and DateTimeOffset.FromUnixTimeSeconds
exist as of .NET 4.6.
Consider using those instead.
If you really need a nullable, you can still wrap the framework methods in an extension method.
Also, generally you should be using DateTimeOffset instead of DateTime unless you explicitly want to ignore timezones (e.g. local noon regardless of timezone). (Somewhat debatable, see comments. Still, as long as you make sure you work in UTC then converting between DateTime
and DateTimeOffset
shouldn't be a problem for Unix time conversion - and certainly no more than it would be a problem with manual calculations.)
Note that DateTimeOffset.ToUnixTimeSeconds
and DateTimeOffset.FromUnixTimeSeconds
exist as of .NET 4.6.
Consider using those instead.
If you really need a nullable, you can still wrap the framework methods in an extension method.
Also, generally you should be using DateTimeOffset instead of DateTime unless you explicitly want to ignore timezones (e.g. local noon regardless of timezone). (Somewhat debatable, see comments. Still, as long as you make sure you work in UTC then converting between DateTime
and DateTimeOffset
shouldn't be a problem for Unix time conversion - and certainly no more than it would be a problem with manual calculations.)
Note that DateTimeOffset.ToUnixTimeSeconds
and DateTimeOffset.FromUnixTimeSeconds
exist as of .NET 4.6.
Consider using those instead.
If you really need a nullable, you can still wrap the framework methods in an extension method.
Also, generally you should be using DateTimeOffset instead of DateTime unless you explicitly want to ignore timezones (e.g. local noon regardless of timezone). (Somewhat debatable, see comments. Still, as long as you make sure you work in UTC then converting between DateTime
and DateTimeOffset
shouldn't be a problem for Unix time conversion - and certainly no more than it would be a problem with manual calculations.)
Note that DateTimeOffset.ToUnixTimeSeconds
and DateTimeOffset.FromUnixTimeSeconds
exist as of .NET 4.6.
Consider using those instead.
If you really need a nullable, you can still wrap the framework methods in an extension method.
Also, generally you should be using DateTimeOffset instead of DateTime unless you explicitly want to ignore timezones (e.g. local noon regardless of timezone).
Note that DateTimeOffset.ToUnixTimeSeconds
and DateTimeOffset.FromUnixTimeSeconds
exist as of .NET 4.6.
Consider using those instead.
If you really need a nullable, you can still wrap the framework methods in an extension method.
Also, generally you should be using DateTimeOffset instead of DateTime unless you explicitly want to ignore timezones (e.g. local noon regardless of timezone). (Somewhat debatable, see comments. Still, as long as you make sure you work in UTC then converting between DateTime
and DateTimeOffset
shouldn't be a problem for Unix time conversion - and certainly no more than it would be a problem with manual calculations.)
Note that DateTimeOffset.ToUnixTimeSeconds
and DateTimeOffset.FromUnixTimeSeconds
exist as of .NET 4.6.
Consider using those instead.
If you really need a nullable, you can still wrap the framework methods in an extension method.
Also, generally you should be using DateTimeOffset instead of DateTime unless you explicitly want to ignore timezones (e.g. local noon regardless of timezone).