「C#でUnixTimeを扱う」の版間の差分

imported>Administrator
編集の要約なし
編集の要約なし
 
(他の1人の利用者による、間の1版が非表示)
1行目: 1行目:
DateTimeの拡張メソッドを用意しておくと便利。
<syntaxhighlight lang="csharp">
<syntaxhighlight lang="csharp">
    public static class DateTimeExtensions  
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)
     {
     {
         private static readonly DateTime UNIX_EPOCH = new DateTime(1970, 1, 1, 0, 0, 0, DateTimeKind.Utc);
         double nowTicks = (dateTime.ToUniversalTime() - UNIX_EPOCH).TotalSeconds;
 
        return (long)nowTicks;
        public static long ToUnixTime(this DateTime dateTime)
    }         
        {
}
            double nowTicks = (dateTime.ToUniversalTime() - UNIX_EPOCH).TotalSeconds;
            return (long)nowTicks;
        }         
    }
</syntaxhighlight>
</syntaxhighlight>
[[カテゴリ:.NET]]
[[カテゴリ:.NET]]