现在的位置: 首页 > 综合 > 正文

C# 时间日期

2012年10月12日 ⁄ 综合 ⁄ 共 1609字 ⁄ 字号 评论关闭
   1: using System;  // 包括所有的date/time

   2:  

   3: class testDateTime

   4: {

   5:   public static void Main()

   6:   {

   7:     DateTime CurrTime = DateTime.Now;

   8:  

   9:     Console.WriteLine("DateTime display listing specifier and result:\n");

  10:  

  11:     Console.WriteLine("d = {0:d}", CurrTime );  // Short date mm/dd/yyyy

  12:     Console.WriteLine("D = {0:D}", CurrTime );  // Long date day, month dd, yyyy

  13:     Console.WriteLine("f = {0:f}", CurrTime );  // Full date/short time day, month dd, yyyy hh:mm

  14:     Console.WriteLine("F = {0:F}", CurrTime );  // Full date/full time day, month dd, yyyy HH:mm:ss AM/PM

  15:     Console.WriteLine("g = {0:g}", CurrTime );  // Short date/short time mm/dd/yyyy HH:mm

  16:     Console.WriteLine("G = {0:G}", CurrTime );  // Short date/long time mm/dd/yyyy hh:mm:ss

  17:     Console.WriteLine("M = {0:M}", CurrTime );  // Month dd

  18:     Console.WriteLine("R = {0:R}", CurrTime );  // ddd Month yyyy hh:mm:ss GMT

  19:     Console.WriteLine("s = {0:s}", CurrTime );  // yyyy-mm-dd hh:mm:ss  can be sorted!

  20:     Console.WriteLine("t = {0:t}", CurrTime );  // Short time hh:mm AM/PM

  21:     Console.WriteLine("T = {0:T}", CurrTime );  // Long time hh:mm:ss AM/PM

  22:     Console.WriteLine("u = {0:u}", CurrTime );  // yyyy-mm-dd hh:mm:ss  universal/sortable

  23:     Console.WriteLine("U = {0:U}", CurrTime );  // day, month dd, yyyy hh:mm:ss AM/PM

  24:     Console.WriteLine("Y = {0:Y}", CurrTime );  // Month, yyyy

  25:     Console.WriteLine();

  26:     Console.WriteLine("DateTime.Month     = " + CurrTime.Month);      // number of month

  27:     Console.WriteLine("DateTime.DayOfWeek = " + CurrTime.DayOfWeek);  // full name of day

  28:     Console.WriteLine("DateTime.TimeOfDay = " + CurrTime.TimeOfDay);  // 24 hour time

  29:  

  30:     // number of 100-nanosecond intervals that have elapsed since 1/1/0001, 12:00am

  31:     // useful for time-elapsed measurements

  32:     Console.WriteLine("DateTime.Ticks     = " + CurrTime.Ticks);

  33:  

  34:     Console.Read();  // wait

  35:   }

  36: }

【上篇】
【下篇】

抱歉!评论已关闭.