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 344 views
1 answer 229 views
1 answer 256 views
1 answer 225 views
2 answers 334 views
1 answer 273 views
3 answers 409 views
...