Hiển thị ngày tháng hiện tại trong CSharp? (How to display current date and time in CSharp?)


Bài viết này ta sẽ hiểu cách để lấy ngày giờ hiện tai trong ngôn ngữ lâp trình C# và hiển thị nó ra màn hình console.





DateTime.Now

Là một thuộc tính(property) cơ bản của DateTime, nó được sử dụng để lấy ngày và giờ hiện tại trên computer của bạn.


Cú pháp - Syntax

public static DateTime Now { get; }


Ví dụ - Example

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

namespace GetDateTimeNow
{
    class Program
    {
        static void Main(string[] args)
        {

            Console.WriteLine("\n\n");

            Console.Write("Current Date and Time:" + DateTime.Now);

            Console.ReadLine();

        }
    }
}


Kết quả - Result















No comments:

Post a Comment