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 201 views
1 answer 130 views
1 answer 177 views
1 answer 137 views
2 answers 193 views
1 answer 159 views
3 answers 228 views
...