Bài viết này chúng ta sẽ tìm thêm một thuộc tính mới của DateTime là Today, với thuộc tích này bạn có thể lấy được ngày tháng năm hiện tại, nó tương tự với thuộc tính Now mà chúng ta đã tìm hiểu trước đây.
DateTime.Today
Là một trong những thuộc tính cơ bản của DateTime được sử dụng để lấy ngày tháng năm hiện tai trên máy ví tính(computer) của bạn.
Giá trị ngày hiện tại được thể hiện trong thuộc tính này vẫn có tồn tại giá trị thời gian(time) nhưng nó được thiết lập mặc định là 00:00:00 (12:00:00 AM).
Cú pháp - Syntax
public static DateTime Today { get; }
Ví dụ - Example
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace GetDateTimeCurrent
{
class Program
{
static void Main(string[] args)
{
// Get the current date.
DateTime thisDay = DateTime.Today;
Console.WriteLine("\n\n\n");
// Display the date in the default (general) format.
Console.WriteLine("Current day: " + thisDay.ToString());
Console.ReadLine();
}
}
}
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace GetDateTimeCurrent
{
class Program
{
static void Main(string[] args)
{
// Get the current date.
DateTime thisDay = DateTime.Today;
Console.WriteLine("\n\n\n");
// Display the date in the default (general) format.
Console.WriteLine("Current day: " + thisDay.ToString());
Console.ReadLine();
}
}
}
Kết quả - Result
No comments:
Post a Comment