2
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

C#で今日の日付と時刻の取得をする

Posted at

初めに

このブログでは、授業で習ったことや自分で勉強したことなどをまとめて記事にしています。

今回は今日の日付と現在の時刻を取得するプログラムを作成しました。

ソースコード

Program.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ConsoleApplication2
{
    class Program
    {
        static void Main(string[] args)
        {
                    // 今日の日付、現在の時刻を取得する

             DateTime dt = DateTime.Now;

             Console.WriteLine("今日の日付と時刻は;"+dt);


             Console.ReadKey();
        }
    }
}

DateTimeの部分で現在のコンピューターの時刻を取ってきています。
あとは、それをWriteLineを使用して表示するだけです

ちなみに
DateTime.Nowではなく、DateTime.Dateなどにすると日付の部分のみを取得します。

まとめ

個人的にJavaで時間を取得するよりC#の取得の方が楽に感じました。

最後まで読んでくれてありがとうございました。

2
2
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
2
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?