开发者

int.ToString like HH formatted of DateTime

开发者 https://www.devze.com 2022-12-23 02:25 出处:网络
(\"dd/MM/yyyy HH\")+ \" - \" + (x.Hour+1).ToString(); So here is example what I got and what I need : 0--->00
("dd/MM/yyyy HH")+ " - " + (x.Hour+1).ToString();

So here is example

what I got and what I need :

0  --->   00 
3  --->   03 
12 --->   12

How can I use ToString for it ?

I've tried :

x.ToString("dd/MM/yyyy HH") + " - " + x.AddHours(1).ToString("HH");

does开发者_JAVA技巧n't works ...


If you just need to make int.ToString having sum leading zeros you can do it like this:

    int integer = 5;
    string str = integer.ToString("00"); // str has "05".


Assuming that x is a valid DateTime, this example works (9am appears as "09").

        DateTime x = DateTime.Now;

        string hours = x.AddHours(1).ToString("HH");
0

精彩评论

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