I am trying to get the current time:
date = "(" + DateTime.Today.Year.ToString() + "-" +
DateTime.Today.Month.ToString() + "-" + DateTime.Today.Day.ToString() + " " +
"(" + DateTime.Today.Hour.ToString() + ":" + DateTime.Today.Minute.ToString()
+")" + ")";
This should get a date like:
(2013-2-1 (13:01))
But it give me:
(2013-2-1 (0:0))
How can i fix this?
You're using DateTime.Today
which is documented as:
An object that is set to today's date, with the time component set to 00:00:00.
So yes, if you find the Hour
and Minute
components, they will be 0...
If you want the current time of day, use DateTime.Now
instead. Note that both Today
and Now
use the system-local time zone - you need to be sure that that really is what you want to use. (It's probably fine for a local client app, but not for a web app.)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With