差分

ナビゲーションに移動 検索に移動

C#でUnixTimeを扱う

425 バイト追加, 2018年8月14日 (火) 04:35
ページの作成:「<syntaxhighlight lang="csharp"> public static class DateTimeExtensions { private static readonly DateTime UNIX_EPOCH = new DateTime(1970, 1, 1, 0, 0, 0,...」
<syntaxhighlight lang="csharp">
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;
}
}
</syntaxhighlight>
匿名利用者

案内メニュー