ISO 8601/RFC 3339 Compatible Dates

There are not standard format specifiers for date that takes a date and converts it to an ISO 8601 or RFC 3339 compatible date. Here are two extension methods that does just that.

public static string ToISO8601(this DateTime date)
{
    return date.ToString("yyyy-MM-dd");
}

public static string ToRFC3339(this DateTime date)
{
    return date.ToUniversalTime().ToString("yyyy-MM-ddThh:mm:ssZ");
}
About these ads


Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Connecting to %s

Follow

Get every new post delivered to your Inbox.