header
CodePanic! > C#.NET Tips > 今ここ

■現在の日付と時刻を取得する

DateTime構造体のNowプロパティーを参照します。
その結果を出力する関数群(一部)とその結果は次の通りです。

using System;
using System.Collections.Generic;
using System.Text;

namespace ConsoleApplication1
{
    class Program
    {
        static void Main(string[] args)
        {
            // 現在の日付と時刻を取得する
            DateTime date = DateTime.Now;

            Console.WriteLine(date.ToString());
            Console.WriteLine(date.ToLongDateString());
            Console.WriteLine(date.ToShortDateString());
            Console.WriteLine(date.ToLongTimeString());
            Console.WriteLine(date.ToShortTimeString());
        }
    }
}

【結果】

2008/08/05 9:50:06
2008年8月5日
2008/08/05
9:50:06
9:50





Copyright © 2008.07 - shougo suzaki