本文整理匯總了C#中System.DateTimeOffset.Now屬性的典型用法代碼示例。如果您正苦於以下問題:C# DateTimeOffset.Now屬性的具體用法?C# DateTimeOffset.Now怎麽用?C# DateTimeOffset.Now使用的例子?那麽, 這裏精選的屬性代碼示例或許可以為您提供幫助。您也可以進一步了解該屬性所在類System.DateTimeOffset
的用法示例。
在下文中一共展示了DateTimeOffset.Now屬性的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的C#代碼示例。
示例1: Main
//引入命名空間
using System;
public class Example
{
public static void Main()
{
String[] fmtStrings = { "d", "D", "f", "F", "g", "G", "M",
"R", "s", "t", "T", "u", "y" };
DateTimeOffset value = DateTimeOffset.Now;
// Display date in default format.
Console.WriteLine(value);
Console.WriteLine();
// Display date using each of the specified formats.
foreach (var fmtString in fmtStrings)
Console.WriteLine("{0} --> {1}",
fmtString, value.ToString(fmtString));
}
}
輸出:
11/19/2012 10:57:11 AM -08:00 d --> 11/19/2012 D --> Monday, November 19, 2012 f --> Monday, November 19, 2012 10:57 AM F --> Monday, November 19, 2012 10:57:11 AM g --> 11/19/2012 10:57 AM G --> 11/19/2012 10:57:11 AM M --> November 19 R --> Mon, 19 Nov 2012 18:57:11 GMT s --> 2012-11-19T10:57:11 t --> 10:57 AM T --> 10:57:11 AM u --> 2012-11-19 18:57:11Z y --> November, 2012
示例2: if
DateTimeOffset dto;
int ctr = 0;
int ms = 0;
do {
dto = DateTimeOffset.Now;
if (dto.Millisecond != ms)
{
ms = dto.Millisecond;
Console.WriteLine("{0}:{1:d3} ms. {2}",
dto.ToString("M/d/yyyy h:mm:ss"),
ms, dto.ToString("zzz"));
ctr++;
}
} while (ctr < 100);