C # ToString ("MM / dd / yy") removes leading 0

Possible duplicate:
.NET DateTime Day format without a null value

Is there any way to remove leading zeros in date format

For example, X.ToString("MM/dd/yy") returns 07/02/11, but I would like 7/2/11 to return instead.

Is it possible?

thank

+14
tostring date c #
Jul 25 '11 at 18:27
source share
5 answers

X.ToString("M/d/yy") is what you need

+24
Jul 25 '11 at 18:31
source share

Just remove the extra M and d .

+6
Jul 25 '11 at 18:30
source share

You can use "M/d/yy" . See here for more details.

+4
Jul 25 '11 at 18:31
source share

You can write X.ToString("M/d/yy")

+1
Jul 25 '11 at 18:33
source share

This is X.ToString("M/d/y") if you want to remove ALL leading zeros;)

+1
Jul 25 '11 at 18:33
source share



All Articles