How to get the current date and time with milliseconds accuracy in C#

1 Answer

0 votes
using System;
using System.Globalization;

class Program
{
    static void Main() {
        string datetime = DateTime.UtcNow.ToString("yyyy-MM-dd HH:mm:ss.fff", 
                                                    CultureInfo.InvariantCulture);

        Console.Write(datetime);
    }
}




/*
run:

2022-03-26 06:49:51.751

*/

 



answered Mar 26, 2022 by avibootz
...