Literal four = new Literal();
string timeanddate;
timeanddate = DateTime.UtcNow.ToString();
DateTime dt = new DateTime();
DateTime dt_calc = new DateTime();
dt = Convert.ToDateTime(timeanddate);
dt_calc = dt.AddHours(3);
four.Text = "3hr added and this gives>> " + dt_calc.ToString();
form1.Controls.Add(four);
its all in AM PM i want to work with 24hrs
See this page for every way you could possibly want to format a DateTime
.
Note that you use "HH" for 24-hour time.
For example, if you wanted the format "23:00:00" instead of "11:00:00 PM" you would use:
string formatted = dt_calc.ToString("HH:mm:ss");
By the way, your initialization of your DateTime
values with new DateTime()
is unnecessary.
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