开发者

Add 12 hours to time.now in c#

I 开发者_开发问答am adding 12 hours to the current time. but the current time is displayed in the text box, what is wrong with the code

 DateTime expiresAt = System.DateTime.Now.AddHours(12);
 txt_ExpiresBy.Text = expiresAt.ToString(@"dd/MM/yyyy hh:mm:ss");


Maybe you are adding 12 hours and you don't see the difference between X AM and X PM?
Try using HH (hour in 24 hours format) instead of hh (hour in 12 hours format) in the format string, or adding the AM/PM indicator tt:

// 24 hours format
expiresAt.ToString(@"dd/MM/yyyy HH:mm:ss");

// 12 hours + am/pm
expiresAt.ToString(@"dd/MM/yyyy HH:mm:ss tt");

See Custom Date and Time Format Strings for a complete reference.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜