Đã có ngày hiện tại thì tất nhiên sẽ có ngày tương lại, mờ cũng có thể là hem :>> thôi kệ nó. Bài này tôi sẽ hướng dẫn cách để lấy ngày tương lai trong ngôn ngữ lập trình C#.
DateTime.AddDays()
Là một phương thức thuộc DateTime được sử dụng để thêm hoặc bớt ngày vào ngày được thiết lập. Hiểu đơn giản nêu bạn thêm tham số 1 thì bạn sẽ có ngày mai(tomorrow) của ngày thiết lập.
Cú pháp - Syntax
public DateTime AddDays(
double value
)
double value
)
Ví dụ - Example
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace GetTomorow
{
class Program
{
static void Main(string[] args)
{
Console.WriteLine("Today: {0}", DateTime.Today);
DateTime y = DateTime.Today.AddDays(1);
Console.WriteLine("Yesterday: {0}", y);
Console.ReadLine();
}
}
}
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace GetTomorow
{
class Program
{
static void Main(string[] args)
{
Console.WriteLine("Today: {0}", DateTime.Today);
DateTime y = DateTime.Today.AddDays(1);
Console.WriteLine("Yesterday: {0}", y);
Console.ReadLine();
}
}
}
Kết quả - Result
No comments:
Post a Comment