Advertisement
imjyb1008work

C# 時間函數

Jun 13th, 2014
568
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.24 KB | None | 0 0
  1. using System;
  2.  
  3. namespace ConsoleApplication1
  4. {
  5.     class Program
  6.     {
  7.         static void Main(string[] args)
  8.         {
  9.             DateTime nowTime = DateTime.Now;
  10.             string strFormat = "{0}:\n{1}\n";
  11.            
  12.             Console.WriteLine(string.Format(strFormat, "nowTime", nowTime));
  13.             //2014/6/13 15:37:15
  14.  
  15.             Console.WriteLine(string.Format(strFormat, "nowTime.Date", nowTime.Date));
  16.             //2014/6/13 00:00:00
  17.  
  18.             Console.WriteLine(string.Format(strFormat, "nowTime.DayOfWeek", nowTime.DayOfWeek));
  19.             //Friday
  20.  
  21.             Console.WriteLine(string.Format(strFormat, "nowTime.DayOfYear", nowTime.DayOfYear));
  22.             //164
  23.  
  24.             Console.WriteLine(string.Format(strFormat, "nowTime.Hour", nowTime.Hour));
  25.             //15
  26.  
  27.             Console.WriteLine(string.Format(strFormat, "nowTime.Year", nowTime.Year));
  28.             //2014
  29.  
  30.             Console.WriteLine(string.Format(strFormat, "nowTime.Month", nowTime.Month));
  31.             //6
  32.  
  33.             Console.WriteLine(string.Format(strFormat, "nowTime.Day", nowTime.Day));
  34.             //13
  35.  
  36.             Console.WriteLine(string.Format(strFormat, "nowTime.Hour", nowTime.Hour));
  37.             //15
  38.  
  39.             Console.WriteLine(string.Format(strFormat, "nowTime.Minute", nowTime.Minute));
  40.             //37
  41.  
  42.             Console.WriteLine(string.Format(strFormat, "nowTime.Second", nowTime.Second));
  43.             //15
  44.  
  45.             Console.ReadKey();
  46.         }
  47.     }
  48. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement