Baba mba Baba mba - 18 days ago 9
C# Question

How can i display Time and date in only hours and minutes

I wanna show the current date and hours and minutes like this

14-11-2016 10:25

but my code shows
14-11-2016 00:00


my Code

var dateAndTime = DateTime.Today;
var date = dateAndTime.Date;
MessageBox.Show(date.ToString("dd-MM-yyyy HH:mm"));

Answer

You are overcomplicating things. Try this:

var date = DateTime.Now;
MessageBox.Show(date.ToString("dd-MM-yyyy HH:mm"));

Using

var date = dateAndTime.Date;

you say you are only interested in the data part so it will remove the time part.

Comments