「C#でUnixTimeを扱う」の版間の差分
ナビゲーションに移動
検索に移動
imported>Administrator (ページの作成:「<syntaxhighlight lang="csharp"> public static class DateTimeExtensions { private static readonly DateTime UNIX_EPOCH = new DateTime(1970, 1, 1, 0, 0, 0,...」) |
imported>Administrator |
||
11行目: | 11行目: | ||
} | } | ||
</syntaxhighlight> | </syntaxhighlight> | ||
+ | [[カテゴリ:.NET]] |
2018年8月14日 (火) 04:36時点における版
public static class DateTimeExtensions
{
private static readonly DateTime UNIX_EPOCH = new DateTime(1970, 1, 1, 0, 0, 0, DateTimeKind.Utc);
public static long ToUnixTime(this DateTime dateTime)
{
double nowTicks = (dateTime.ToUniversalTime() - UNIX_EPOCH).TotalSeconds;
return (long)nowTicks;
}
}