Neo
Neo

Reputation: 395

DateTime.Today returns wrong Hours / minutes

When I make an output for:

DateTime.Today.ToString("dd-MM-yyyy_HH-mm_tt");

It returns me "08-09-2013_00-00_a.m." instead of "08-09-2013_10-36_p.m." (my current system hour).

What causes this behaviour? Thank you..

Upvotes: 2

Views: 1936

Answers (2)

mshsayem
mshsayem

Reputation: 18008

Use DateTime.Now:

DateTime.Now.ToString("dd-MM-yyyy_HH-mm_tt");

DateTime.Today gives you the date part of current time with the time component set to 00:00:00.

See msdn documentation.

Upvotes: 10

Marcia Ong
Marcia Ong

Reputation: 781

Use DateTime.Now.

Additional info if you want to compare time.

        DateTime start = new DateTime(2013, 6, 14,2,15,20);
        DateTime end = new DateTime(20013, 12, 14);
        TimeSpan difference = end - start;
        int haha = difference.Minutes;
        Console.WriteLine("Difference in days: " + difference.TotalMinutes);

Upvotes: 1

Related Questions