-
UTC datetime format
there must be a better way....
I need to write a datetime to an xml file in the UTC format:
"2008-04-12T14:43:11+00:00"
Obviously i can declare it in DateTime utc, but is there a simple way of making it a string in the above format without having to specify a whole load of arguments as in .tostring("YYYY"-"MM"-"DD" etcetcetcetc)
-
Re: UTC datetime format
Code:
String.Format("{0:yyyy-MM-dd}T{0:HH:mm:ss}+00:00", myDate)
-
Re: UTC datetime format
You just have to call the date object's ToString method and pass in the correct custom format string. Something like this:
Code:
Dim d As Date = Date.Now
MessageBox.Show(d.ToString("yyyy-MM-dd'T'HH:mm:sszzz"))
-
Re: UTC datetime format
Nice tricks in that formatting stanav. I didn't know you could do some of that.
EDIT: Man, you're like the fourth post now that I was impressed by something and clicked "Rate" only to give me a "Spread the love" message. :D
-
Re: UTC datetime format
You can also use the "O" or "o" standard format format string if you don't mind the partial seconds being included too.
MSDN lists all the standard and custom format strings for dates, times and numbers. That's always the first place you should look.
-
Re: UTC datetime format
thanks guys!
thats exactly the sort of neat time saving answer I was hoping for!