Active Directory Products
Calls To Calendar
SMS To CSV
SMS To Gmail
Voicemail To Gmail
How Long For Me
<< 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'");
return df.format(new Date());
Calculating ISO 8601 in Windows C++:
sprintf(buf, "%i-%02i-%02iT%02i:%02i:%02i.%03iZ", tm.wYear, tm.wMonth, tm.wDay, tm.wHour, tm.wMinute, tm.wSecond, tm.wMilliseconds);
Calculating ISO 8601 in UNIX C++:
struct tm 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);
I hope this helps some of you out along the way!
Timestampin' Tom Out.
Creating a reusable web client for PUT, POST, and DELETE in C#
Using MOSS and WSS SharePoint Workflow to Resize Images in an Image Library
A quick way to find C++ method signatures for C# Interop
Reading A Database Schema in SQLite with C#
Currently no comments.
Add A Comment
Email Address: (not public, used to send notifications on further comments)
Enter the text above, except for the 1st and last character: