How to extract the year from datetime into a string with C#

1 Answer

0 votes
using System;

class Test
{
    static void Main() {
        DateTime dt = DateTime.Now;

        string s = string.Format("{0:yyyy}", dt);

        Console.WriteLine(s);
    }
}



 
/*
run:

2022
 
*/

 



answered Oct 30, 2022 by avibootz

Related questions

2 answers 217 views
1 answer 151 views
1 answer 183 views
1 answer 151 views
2 answers 204 views
1 answer 172 views
3 answers 243 views
...