C# year

Use DateTime class to get year.

using System;
DateTime dt = new DateTime(2050, 4, 28);
int y = dt.Year; //2050
dt = dt.AddYears(4);
int y2 = dt.Year; //2054

Use Parse method to load other formats of dates.
using System;
DateTime dt = DateTime.Parse("4/28/2048");
dt = dt.AddYears(4);
int y = dt.Year; //2052



endmemo.com © 2024  | Terms of Use | Privacy | Home