|
-
Sep 11th, 2008, 01:44 PM
#1
Thread Starter
Junior Member
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)
-
Sep 11th, 2008, 01:56 PM
#2
Re: UTC datetime format
Code:
String.Format("{0:yyyy-MM-dd}T{0:HH:mm:ss}+00:00", myDate)
-
Sep 11th, 2008, 01:57 PM
#3
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"))
Let us have faith that right makes might, and in that faith, let us, to the end, dare to do our duty as we understand it.
- Abraham Lincoln -
-
Sep 11th, 2008, 02:00 PM
#4
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.
-
Sep 12th, 2008, 02:00 AM
#5
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.
-
Sep 12th, 2008, 03:22 AM
#6
Thread Starter
Junior Member
Re: UTC datetime format
thanks guys!
thats exactly the sort of neat time saving answer I was hoping for!
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|