DateTimeOffset.ToUnixTimeMilliseconds() Method in C#
DateTimeOffset.ToUnixTimeMilliseconds Method is used to return the number of milliseconds that have elapsed since 1970-01-01T00:00:00.000Z. This method will return a negative value for the date and time values before 1970-01-01T00:00:00Z.
Syntax: public long ToUnixTimeMilliseconds ();
Return Value: This method returns the number of milliseconds that have elapsed since 1970-01-01T00:00:00.000Z.
Below programs illustrate the use of DateTimeOffset.ToUnixTimeMilliseconds() Method:
Example 1:
using System;
using System.Globalization;
class GFG {
public static void Main()
{
DateTimeOffset offset = new DateTimeOffset(2007,
6, 1, 7, 55, 0, new TimeSpan(-5, 0, 0));
long value = offset.ToUnixTimeMilliseconds();
Console.WriteLine( "Returns the number of" +
" milliseconds : {0}" , value);
}
}
|
Output:
Returns the number of milliseconds : 1180702500000
Example 2:
using System;
using System.Globalization;
class GFG {
public static void Main()
{
DateTimeOffset offset = new DateTimeOffset(1960,
6, 1, 7, 55, 0, new TimeSpan(-5, 0, 0));
long value = offset.ToUnixTimeMilliseconds();
Console.WriteLine( "Returns the number " +
"of milliseconds : {0}" , value);
}
}
|
Output:
Returns the number of milliseconds : -302439900000
Reference:
Last Updated :
19 Mar, 2019
Like Article
Save Article
Share your thoughts in the comments
Please Login to comment...