Int.ToString as HH formatted in DateTime

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

So here is an example

what i got and what i need:

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

How can I use ToString for it?

I tried:

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

does not work...

+3
source share
2 answers

If you just need to do an int.ToString with the sum of leading zeros, you can do it like this:

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

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

        DateTime x = DateTime.Now;

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

Source: https://habr.com/ru/post/1736956/


All Articles