Here's the code:
string year = Convert.ToString(formModel.JamKeluar.Year);
int aas = year.IndexOf((char)1);
How can I get the last 3 digit of the year as int? example if the year 2021, I need 21 as int
Here's the code:
string year = Convert.ToString(formModel.JamKeluar.Year);
int aas = year.IndexOf((char)1);
How can I get the last 3 digit of the year as int? example if the year 2021, I need 21 as int
There is the Remainder operator in C#
The remainder operator % computes the remainder after dividing its left-hand operand by its right-hand operand.
int year = formModel.JamKeluar.Year;
int aas = year % 1000;
Console.WriteLine(aas);
You can take last 3 digits like this
string year = Convert.ToString(formModel.JamKeluar.Year);
int aas = Convert.ToInt16(year.Substring(1));
You can try this.
string year = DateTime.Now.Year.ToString();
int n = year.Length;
int treamedYear = int.Parse(string.Format("{0}{1}{2}", year[n - 3], year[n - 2], year[n - 1]));
Console.WriteLine(inttreamedYear);
If you convert it to int
data type, the 0 at the starting position will be removed automatically. If you need that 0, use string.
string treamedYear = string.Format("{0}{1}{2}", year[n - 3], year[n - 2], year[n - 1]);