当前位置: 首页>>代码示例 >>用法及示例精选 >>正文


C# DateTimeOffset.ToUnixTimeMilliseconds()用法及代码示例


DateTimeOffset.ToUnixTimeMilliseconds方法用于返回自1970-01-01T00:00:00.000Z以来经过的毫秒数。对于1970-01-01T00:00:00Z之前的日期和时间值,此方法将返回负值。

用法: public long ToUnixTimeMilliseconds ();

返回值:此方法返回自1970-01-01T00:00:00.000Z以来经过的毫秒数。


以下示例程序旨在说明DateTimeOffset.ToUnixTimeMilliseconds()方法的使用:

范例1:

// C# program to demonstrate the 
// DateTimeOffset.ToUnixTimeMilliseconds() 
// Method 
using System; 
using System.Globalization; 
  
class GFG { 
  
    // Main Method 
    public static void Main() 
    { 
        // creating object of  DateTimeOffset 
        DateTimeOffset offset = new DateTimeOffset(2007, 
                6, 1, 7, 55, 0, new TimeSpan(-5, 0, 0)); 
  
        // Returns the number of milliseconds 
        // instance using ToUnixTimeMilliseconds() method 
        long value = offset.ToUnixTimeMilliseconds(); 
  
        // Display the time 
        Console.WriteLine("Returns the number of"+ 
                    " milliseconds:{0}", value); 
    } 
}
输出:
Returns the number of milliseconds:1180702500000

范例2:

// C# program to demonstrate the 
// DateTimeOffset.ToUnixTimeMilliseconds() 
// Method 
using System; 
using System.Globalization; 
  
class GFG { 
  
    // Main Method 
    public static void Main() 
    { 
        // Creating object of  DateTimeOffset 
        DateTimeOffset offset = new DateTimeOffset(1960, 
                6, 1, 7, 55, 0, new TimeSpan(-5, 0, 0)); 
  
        // Returns the number of milliseconds 
        // instance using ToUnixTimeMilliseconds() method 
        long value = offset.ToUnixTimeMilliseconds(); 
  
        // Display the time 
        Console.WriteLine("Returns the number "+ 
                "of milliseconds:{0}", value); 
    } 
}
输出:
Returns the number of milliseconds:-302439900000

参考:



相关用法


注:本文由纯净天空筛选整理自RohitPrasad3大神的英文原创作品 DateTimeOffset.ToUnixTimeMilliseconds() Method in C#。非经特殊声明,原始代码版权归原作者所有,本译文未经允许或授权,请勿转载或复制。