C#之获取年、月、日、时、分、秒...



//为操作方便,我封闭了一个类,代码如下:

class The_Day
        {
             public static string getTheDay()
             {
                 string strDay = "";
                 string[] Day = new string[] { "星期日", "星期一", "星期二", "星期三", "星期四", "星期五", "星期六" };
                 System.DateTime currentTime = System.DateTime.Now;
                 strDay = currentTime.Year +
                          "年" + currentTime.Month+
                          "月" + currentTime.Day+
                          "日" + currentTime.Hour+
                          "时" + currentTime.Minute+
                          "分" + currentTime.Second+
                          "秒 "+Day[(int)System.DateTime.Now.DayOfWeek];
                 return (strDay);           
             }
        }

//调用代码如下:
Console.WriteLine(The_Day.getTheDay()+" By yxHuang!...");





posted @ 2012-04-11 21:33  氺〤魚Oo。  阅读(353)  评论(0编辑  收藏  举报