Home
IPhone SMS To Gmail
Consulting
Blog
Software
Projects
Links
About
Contact
Blog
Facebook
Twitter
LinkedIn
|
<< Back To All Blogs
Calculating ISO 8601 Date formats in C#, C++, and Java
Thursday, December 11th, 2008
I have done a fair amount of work authenticating against the Amazon web services APIs, not to mention the APIs of other online services, and one thing that is often a difficult and tedious task to calculate is the ISO 8601 Date format that Amazon (and many other) REST APIs require in order to properly authenticate. I thought that I would share my methods of doing so in multiple different programming languages to allow many of you in the future to easily copy this code and use it in your own APIs.
Without further ado, I present my solutions:
Calculating ISO 8601 in C#:
return System.DateTime.UtcNow.ToString("yyyy-MM-ddTHH:mm:ss.fffZ", System.Globalization.CultureInfo.InvariantCulture);
Calculating ISO 8601 in Java:
SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSS'Z'");
df.setTimeZone(TimeZone.getTimeZone("Etc/UTC"));
return df.format(new Date());
Calculating ISO 8601 in Windows C++:
SYSTEMTIME tm;
GetSystemTime(&tm);
char buf[500];
sprintf(buf, "%i-%02i-%02iT%02i:%02i:%02i.%03iZ", tm.wYear, tm.wMonth, tm.wDay, tm.wHour, tm.wMinute, tm.wSecond, tm.wMilliseconds);
return buf;
Calculating ISO 8601 in UNIX C++:
struct tm tm;
char tmp[120];
time_t t;
time(&t);
localtime_r(&t,&tm);
sprintf(tmp, "%i-%02i-%02iT%02i:%02i:%02i", tm.tm_year + 1900, tm.tm_mon+1, tm.tm_mday, tm.tm_hour, tm.tm_min, tm.tm_sec);
return tmp;
I hope this helps some of you out along the way!
Timestampin' Tom Out.
Tags
CSharp
CPP
Java
Related Blogs
A quick way to find C++ method signatures for C# Interop
Reading an XML file using LINQ
Retrieving data from SharePoint SOAP Requests using LINQ
ConnectionString Switcharoo
SharePoint RPC: Corrupted Binary Files
Comments
Currently no comments.
Add A Comment
Name:
URL:
Email Address: (not public, used to send notifications on further comments)
Comments:
Please enter the text from the image:

|