DateTime.Now.ToString("HH:MM") allways gives 20:06

1.5k views Asked by At

In c# i'm trying to get the time with the following code:

DateTime.Now.ToString("HH:MM");

I fill this value into a ListView. Somehow it allways gives 20:06 but if I add a breakpoint before this point in my code and walk through it step by step it show me a different time while it is still adding 20:06.

Here's how i'm adding it:

ListViewItem item = new ListViewItem(mItem.Naam);
item.SubItems.Add(DateTime.Now.ToString("HH:MM"));
item.SubItems.Add(tafelnummer.ToString());

lstBarOverzicht.Items.Add(item);

When i'm going throug the code step by step and hold the mouse on "Now" then I see DateTime.Now {9-6-2015 21:02:15} but when I check the subitems of item then I see the resultview then I see subitems [1] {20:06}

2

There are 2 answers

0
Marc Cals On BEST ANSWER

Just use DateTime.Now.ToString("HH:mm")) instead of "HH:MM" "MM" is for format as month, "mm" is for minutes.

0
James Harcourt On

You're asking to show HOUR:MONTH.

You need:

item.SubItems.Add(DateTime.Now.ToString("HH:mm"));