Languages
[Edit]
EN

C# / .NET - get current date and time

5 points
Created by:
AnnLen
1777

In C# / .NET DateTime structure allows to take current date and time.

1. Current date and time example

DateTime now = DateTime.Now;
DateTime date = now.Date;

Console.WriteLine(now.ToString());
Console.WriteLine(date.ToString());

Output:

13.08.2019 21:15:45
13.08.2019 00:00:00

2. Current UTC example

DateTime now = DateTime.UtcNow;
DateTime date = now.Date;

Console.WriteLine(now.ToString());
Console.WriteLine(date.ToString());

Output:

13.08.2019 20:15:46
13.08.2019 00:00:00

References

  1. Coordinated Universal Time (UTC) - Wikipedia
Hey 👋
Would you like to know what we do?
  • Dirask is a friendly IT community for learners, professionals and hobbyists to share their knowledge and help each other in extraordinary easy way.
  • We welcome everyone,
    no matter what the experience,
    no matter how basic the question is,
    this community will help you.