Input String was not in a correct format
I have a label on a page load event that I'm trying to display the current date and time in the long format and have this line of code:
Code:
TimeDateLabel.Text = String.Format("Today's date is {D}", DateTime.Now)
but when I load the page I am presented with the error that the Input String was not in a correct format. I thought that that format was correct. Can anyone tell me what is wrong with my format?
Thank you
Doug
Re: Input String was not in a correct format
When you use String.Format, all place-holders must have a number that refers to the index of a parameter. The first parameter is number 0, the second is number 1, etc. If you then want to provide a format string as well, you follow the number with a colon and then the format string. Your code should be:
Code:
TimeDateLabel.Text = String.Format("Today's date is {0:D}", DateTime.Now)