{"id":63713,"date":"2022-01-20T07:00:52","date_gmt":"2022-01-20T06:00:52","guid":{"rendered":"https:\/\/drafts.code-maze.com\/?p=63713"},"modified":"2024-02-01T15:34:16","modified_gmt":"2024-02-01T14:34:16","slug":"convert-datetime-to-iso-8601-string-csharp","status":"publish","type":"post","link":"https:\/\/code-maze.com\/convert-datetime-to-iso-8601-string-csharp\/","title":{"rendered":"Convert DateTime to ISO 8601 String in C#"},"content":{"rendered":"<p>In this article, we are going to learn how to convert DateTime to ISO 8601 string in C#. There are various formats of ISO 8601 compliant date and time strings. We are going to build a console application and explore all these different formats.\u00a0<\/p>\n<div style=\"padding: 20px; border-left: 5px #dc2323 solid; display: block; margin-bottom: 20px; box-shadow: 1px 1px 5px 0px lightgrey;\">To download the source code for this article, you can visit our <a href=\"https:\/\/github.com\/CodeMazeBlog\/CodeMazeGuides\/tree\/main\/dotnet-datetime\/ConvertDateTimeToIso8601String\" target=\"_blank\" rel=\"nofollow noopener\">GitHub repository<\/a>.<\/div>\n<p>Let&#8217;s start.<\/p>\n<h2 id=\"standard-formats\">Standard DateTime Format Strings<\/h2>\n<p>The standard <code>DateTime<\/code> format specifier is the most convenient way to get an <a href=\"http:\/\/en.wikipedia.org\/wiki\/ISO_8601\" target=\"_blank\" rel=\"nofollow noopener\">ISO 8601<\/a> output. While there are many standard format specifiers, only three of them can give us ISO 8601 compliant output: &#8220;<strong>s<\/strong>&#8220;, &#8220;<strong>o<\/strong>&#8220;, &#8220;<strong>u<\/strong>&#8220;.<\/p>\n<p>To begin, let&#8217;s update our <code>Program<\/code> class and declare two <code>DateTime<\/code> objects, one local and another as a UTC standard type:<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"csharp\">var localTime = new DateTime(2022, 1, 13, 16, 25, 35, 125, DateTimeKind.Local);\r\nvar utcTime = new DateTime(2022, 1, 13, 16, 25, 35, 125, DateTimeKind.Utc);\r\n<\/pre>\n<p>Now, let&#8217;s explore the different specifiers.<\/p>\n<h3>Sortable Format Specifier (&#8220;s&#8221;)<\/h3>\n<p>The sortable format specifier (&#8220;<strong>s<\/strong>&#8220;) is useful to get an ISO 8601 compliant sortable string:<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"csharp\">Console.WriteLine($\"Local: {localTime.ToString(\"s\")}\"); \/\/ 2022-01-13T16:25:35\r\nConsole.WriteLine($\"UTC: {utcTime.ToString(\"s\")}\");     \/\/ 2022-01-13T16:25:35<\/pre>\n<p>This is the most common way of getting ISO 8601 compliant <code>DateTime<\/code> strings.<\/p>\n<h3>Round-trip Format Specifier (&#8220;o&#8221;)<\/h3>\n<p>The round-trip format specifier (&#8220;<strong>o<\/strong>&#8220;) is useful to get an ISO 8601 string which includes time-zone information:<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"csharp\">Console.WriteLine($\"Local: {localTime.ToString(\"o\")}\"); \/\/ 2022-01-13T16:25:35.1250000+06:00\r\nConsole.WriteLine($\"UTC: {utcTime.ToString(\"o\")}\");     \/\/ 2022-01-13T16:25:35.1250000Z<\/pre>\n<p>We can see that the output of <code>localTime<\/code> includes the time-zone information at the end (<strong>+6:00<\/strong>) which is interpreted as <code>UTC+06:00<\/code>. In contrast, <code>utcTime<\/code> prints just &#8216;<strong>Z<\/strong>&#8216; at the end, which complies with the ISO 8601 standard for <code>UTC+00:00<\/code> DateTime. In addition, the output contains the fraction of seconds part up to 7 digits. This is why round-trip format is recommended when accuracy is an important concern.<\/p>\n<h3>Universal Format Specifier (&#8220;u&#8221;)<\/h3>\n<p>While working with <code>DateTime<\/code>, it&#8217;s a common scenario to get the output directly in UTC value as well as in ISO 8601 compliant format. We can use the universal format specifier (&#8220;<strong>u<\/strong>&#8220;) for such cases.<\/p>\n<p>Unlike the previous two cases, we need slight customization here, so let&#8217;s create an extension method:<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"csharp\">public static string ToUniversalIso8601(this DateTime dateTime)\r\n{\r\n    return dateTime.ToUniversalTime().ToString(\"u\").Replace(\" \", \"T\");\r\n}<\/pre>\n<p>In this method, we convert the date to UTC value and then format it using <code>ToString(\"u\")<\/code>. Furthermore, we replace whitespace with &#8220;<strong>T<\/strong>&#8220;. This is because ISO 8601 does not allow whitespace as the date-time separator but expects &#8220;<strong>T<\/strong>&#8221; instead. So, we have our extension method ready for standard ISO 8601 compliant UTC output:<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"csharp\">Console.WriteLine($\"Local: {localTime.ToUniversalIso8601()}\");  \/\/ 2022-01-13T10:25:35Z\r\nConsole.WriteLine($\"UTC: {utcTime.ToUniversalIso8601()}\");      \/\/ 2022-01-13T16:25:35Z<\/pre>\n<p>As expected, the resulting strings are all in UTC standard.<\/p>\n<h2 id=\"custom-formats\">Custom DateTime Format Strings<\/h2>\n<p><strong>The standard C# format strings can&#8217;t cover all the output patterns that ISO 8601 supports.<\/strong> But, we have <a href=\"https:\/\/docs.microsoft.com\/en-us\/dotnet\/standard\/base-types\/custom-date-and-time-format-strings\" target=\"_blank\" rel=\"nofollow noopener\">custom format strings<\/a> that can cover the majority of the cases.<\/p>\n<p>Similarly to the standard formats, we can simply call the <code>ToString<\/code> method with the custom format:<\/p>\n<p><code class=\"EnlighterJSRAW\" data-enlighter-language=\"csharp\">var output = localTime.ToString(\"yyyy-MM-ddTHH:mm:ssK\");<\/code><\/p>\n<p><strong>Not all custom formats are ISO 8601 compliant.<\/strong> According to ISO 8601 rules, we can use various combinations of date and time formats as long as the format honors the chronological order of date and time components. There are certain other restrictions, too. For example, we can use &#8220;yyyy-MM&#8221; but not &#8220;yyyyMM&#8221; which is prohibited because of ambiguity.<\/p>\n<h3>ISO 8601 Compliant Custom DateTime Formats<\/h3>\n<p>So, what are the supported formats then? Let&#8217;s have a look at this table of some compliant formats along with their effect on <code>localTime<\/code>:<\/p>\n\n<table id=\"tablepress-19\" class=\"tablepress tablepress-id-19\">\n<thead>\n<tr class=\"row-1\">\n\t<th class=\"column-1\">Format<\/th><th class=\"column-2\">Output<\/th><th class=\"column-3\">Type<\/th>\n<\/tr>\n<\/thead>\n<tbody class=\"row-striping row-hover\">\n<tr class=\"row-2\">\n\t<td class=\"column-1\">yyyy-MM-dd<\/td><td class=\"column-2\">2022-01-13<\/td><td class=\"column-3\">Calendar Date<\/td>\n<\/tr>\n<tr class=\"row-3\">\n\t<td class=\"column-1\">yyyyMMdd<\/td><td class=\"column-2\">20220113<\/td><td class=\"column-3\">Calendar Date<\/td>\n<\/tr>\n<tr class=\"row-4\">\n\t<td class=\"column-1\">yyyy-MM<\/td><td class=\"column-2\">2022-01<\/td><td class=\"column-3\">Calendar Date<\/td>\n<\/tr>\n<tr class=\"row-5\">\n\t<td class=\"column-1\">\u2013MM-dd<\/td><td class=\"column-2\">\u201301-13<\/td><td class=\"column-3\">Calendar Date<\/td>\n<\/tr>\n<tr class=\"row-6\">\n\t<td class=\"column-1\">\u2013MMdd<\/td><td class=\"column-2\">\u20130113<\/td><td class=\"column-3\">Calendar Date<\/td>\n<\/tr>\n<tr class=\"row-7\">\n\t<td class=\"column-1\">THH:mm:ss.fff<\/td><td class=\"column-2\">T16:25:35.125<\/td><td class=\"column-3\">Time<\/td>\n<\/tr>\n<tr class=\"row-8\">\n\t<td class=\"column-1\">THH:mm:ss<\/td><td class=\"column-2\">T16:25:35<\/td><td class=\"column-3\">Time<\/td>\n<\/tr>\n<tr class=\"row-9\">\n\t<td class=\"column-1\">THH:mm<\/td><td class=\"column-2\">T16:25<\/td><td class=\"column-3\">Time<\/td>\n<\/tr>\n<tr class=\"row-10\">\n\t<td class=\"column-1\">THH<\/td><td class=\"column-2\">T16<\/td><td class=\"column-3\">Time<\/td>\n<\/tr>\n<tr class=\"row-11\">\n\t<td class=\"column-1\">THHmmssfff<\/td><td class=\"column-2\">T162535125<\/td><td class=\"column-3\">Time<\/td>\n<\/tr>\n<tr class=\"row-12\">\n\t<td class=\"column-1\">yyyyMMddTHHmmssK<\/td><td class=\"column-2\">20220113T162535+06:00<\/td><td class=\"column-3\">Date and Time<\/td>\n<\/tr>\n<tr class=\"row-13\">\n\t<td class=\"column-1\">yyyyMMddTHHmm<\/td><td class=\"column-2\">20220113T1625<\/td><td class=\"column-3\">Date and Time<\/td>\n<\/tr>\n<tr class=\"row-14\">\n\t<td class=\"column-1\">yyyy-MM-ddTHH:mmZ<\/td><td class=\"column-2\">2022-01-13T16:25Z<\/td><td class=\"column-3\">Date and Time<\/td>\n<\/tr>\n<tr class=\"row-15\">\n\t<td class=\"column-1\">yyyyMMddTHHmmsszzz<\/td><td class=\"column-2\">20220113T162535+06:00<\/td><td class=\"column-3\">Date and Time<\/td>\n<\/tr>\n<tr class=\"row-16\">\n\t<td class=\"column-1\">yyyyMMddTHHmmsszz<\/td><td class=\"column-2\">20220113T162535+06<\/td><td class=\"column-3\">Date and Time<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<!-- #tablepress-19 from cache -->\n<h3>Custom Formats with Time Zone<\/h3>\n<p>We&#8217;ve used several custom formats that include special characters &#8216;<strong>Z<\/strong>&#8216;, &#8216;<strong>z<\/strong>&#8216;, and &#8216;<strong>K<\/strong>&#8216;. It&#8217;s worth knowing a bit more about them as they have an essential role in producing ISO 8601 compliant output with time-zone information.<\/p>\n<p>&#8216;<strong>Z<\/strong>&#8216; <strong>does not have any special interpretation as a C# formatting literal<\/strong>, but does have special meaning from ISO 8601 perspective. Any date string with &#8216;<strong>Z<\/strong>&#8216; appended at the end implies that it represents a UTC <code>DateTime<\/code>.<\/p>\n<p><strong>In contrast, &#8216;z&#8217; and &#8216;K&#8217; are purely C# formatting literals that add time zone information based on the <\/strong><code>DateTimeKind<\/code> <strong>value associated with the <code>DateTime<\/code> object<\/strong>. While &#8216;<strong>K<\/strong>&#8216; provides full time-zone phrase, &#8216;<strong>z<\/strong>&#8216; offers flexibility to print in a short phrase:<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"csharp\">var format = \"yyyy-MM-ddTHH:mm:ssK\";\r\nvar unspecified = new DateTime(2022, 1, 13, 16, 25, 30, DateTimeKind.Unspecified);\r\nvar utc = new DateTime(2022, 1, 13, 16, 25, 30, DateTimeKind.Utc);\r\nvar local = new DateTime(2022, 1, 13, 16, 25, 30, DateTimeKind.Local);\r\n\r\nConsole.WriteLine(unspecified.ToString(format));            \/\/ 2022-01-13T16:25:30\r\nConsole.WriteLine(utc.ToString(format));                    \/\/ 2022-01-13T16:25:30Z\r\nConsole.WriteLine(local.ToString(format));                  \/\/ 2022-01-13T16:25:30+06:00\r\nConsole.WriteLine(local.ToString(\"yyyy-MM-ddTHH:mm:sszz\")); \/\/ 2022-01-13T16:25:30+06<\/pre>\n<p><span style=\"font-weight: 400;\">We can see that the time zones have been applied to the resulting strings as expected.<\/span><\/p>\n<h2 id=\"week-dates\">Week Dates<\/h2>\n<p>ISO 8601 week date patterns are something that we can&#8217;t produce directly using format strings. So, we are going to build extension methods that can give us the desired outputs.<\/p>\n<p>Week dates can be presented in two forms:<\/p>\n<ul>\n<li>&#8220;<strong>yyyy<\/strong>-W<strong>ww<\/strong>&#8220;<\/li>\n<li>&#8220;<strong>yyyy<\/strong>-W<strong>ww<\/strong>&#8211;<strong>D<\/strong>&#8220;<\/li>\n<\/ul>\n<p>Here, [<strong>ww<\/strong>] stands for weak of the year in number, and [<strong>D<\/strong>] stands for the day of the week in number. We can also omit the separators (&#8216;-&#8216;). For example, our <code>localTime<\/code> date can be presented as &#8220;<strong>2022-W03<\/strong>&#8221; or &#8220;<strong>2022W03<\/strong>&#8221; in short form and &#8220;<strong>2022-W03-4<\/strong>&#8221; or &#8220;<strong>2022W034<\/strong>&#8221; in extended form.\u00a0<\/p>\n<p>Let&#8217;s create our extension methods for both short and extended versions:<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"csharp\">public static string ToShortIso8601WeekDateString(this DateTime dateTime, bool useSeparator = true) \r\n{ \r\n    var separator = useSeparator ? \"-\" : string.Empty; \r\n    var culture = CultureInfo.InvariantCulture; \r\n    var format = culture.DateTimeFormat; \r\n\r\n    var weekOfYear = culture.Calendar.GetWeekOfYear(dateTime, format.CalendarWeekRule, format.FirstDayOfWeek);\r\n    var weekPlaceHolder = $\"{weekOfYear}\".PadLeft(2, '0');\r\n\r\n    return $\"{dateTime.Year}{separator}W{weekPlaceHolder}\"; \r\n}\r\n\r\npublic static string ToExtendedIso8601WeekDateString(this DateTime dateTime, bool useSeparator = true) \r\n{ \r\n    var separator = useSeparator ? \"-\" : string.Empty; \r\n\r\n    return $\"{dateTime.ToShortIso8601WeekDateString(useSeparator)}{separator}{(int)dateTime.DayOfWeek}\"; \r\n}<\/pre>\n<p>In the first method, we use invariant culture because ISO 8601 does not allow culture-specific outputs. We get two necessary pieces of information from this <code>culture<\/code>\u00a0instance: <code>DateTimeFormat<\/code> and <code>Calendar<\/code>. Subsequently, we retrieve the week number using the calendar&#8217;s <code>GetWeekOfYear<\/code> method. Finally, we render this week number with necessary padding because the [<strong>ww<\/strong>] placeholder needs to be filled in full:<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"csharp\">\/\/ Week dates - short form\r\nConsole.WriteLine(localTime.ToShortIso8601WeekDateString());                        \/\/ 2022-W03\r\nConsole.WriteLine(localTime.ToShortIso8601WeekDateString(useSeparator: false));     \/\/ 2022W03\r\n\r\n\/\/ Week dates - extended form\r\nConsole.WriteLine(localTime.ToExtendedIso8601WeekDateString());                     \/\/ 2022-W03-4\r\nConsole.WriteLine(localTime.ToExtendedIso8601WeekDateString(useSeparator: false));  \/\/ 2022W034<\/pre>\n<p>Nice! We have the output in desired week date formats.<\/p>\n<p>If you&#8217;re interested in more useful stuff about week dates, check out: <a href=\"https:\/\/code-maze.com\/csharp-datetime-weekend-weekday\/\" target=\"_blank\" rel=\"noopener\">Check if DateTime is Weekend or Weekday<\/a>.\u00a0\u00a0<\/p>\n<h2 id=\"ordinal-dates\">Ordinal Dates<\/h2>\n<p>Similarly to the week dates, we will need custom solutions for ISO 8601 ordinal date patterns. Ordinal dates can be represented as &#8220;<strong>yyyy<\/strong>&#8211;<strong>DDD<\/strong>&#8221; or &#8220;<strong>yyyyDDD<\/strong>&#8221; where [<strong>DDD<\/strong>] indicates the day of the year.<\/p>\n<p>Let&#8217;s create an extension method named <code>ToIso8601OrdinalDateString<\/code> to manage the ordinal dates:<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"csharp\">public static string ToIso8601OrdinalDateString(this DateTime dateTime, bool useSeparator = true) \r\n{ \r\n    var separator = useSeparator ? \"-\" : string.Empty; \r\n    var dayPlaceHolder = $\"{dateTime.DayOfYear}\".PadLeft(3, '0');\r\n    \r\n    return $\"{dateTime.Year}{separator}{dayPlaceHolder}\"; \r\n}<\/pre>\n<p>In this method, we retrieve the day of the year and render it with appropriate padding to comply with the [<strong>DDD<\/strong>] pattern:<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"csharp\">Console.WriteLine(localTime.ToIso8601OrdinalDateString());                      \/\/ 2022-013\r\nConsole.WriteLine(localTime.ToIso8601OrdinalDateString(useSeparator: false));   \/\/ 2022013<\/pre>\n<p>So, we now have the desired output in ordinal date format.<\/p>\n<h2>Conclusion<\/h2>\n<p>In this article, we have learned a few different ways to convert DateTime to ISO 8601 string in C#. We have also built some useful extension methods that can convert DateTime to complex ISO 8601 patterns including week dates and ordinal dates.<\/p><\/p>\n","protected":false},"excerpt":{"rendered":"<p>In this article, we are going to learn how to convert DateTime to ISO 8601 string in C#. There are various formats of ISO 8601 compliant date and time strings. We are going to build a console application and explore all these different formats.\u00a0 Let&#8217;s start. Standard DateTime Format Strings The standard DateTime format specifier [&hellip;]<\/p>\n","protected":false},"author":38,"featured_media":62189,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_et_pb_use_builder":"","_et_pb_old_content":"","_et_gb_content_width":"","footnotes":""},"categories":[12,1049],"tags":[10,1002,1030,242],"class_list":["post-63713","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-csharp","category-datetime","tag-net","tag-datetime","tag-iso-8691","tag-string","et-has-post-format-content","et_post_format-et-post-format-standard"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v24.7 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>Convert DateTime to ISO 8601 String in C# - Code Maze<\/title>\n<meta name=\"description\" content=\"Explain various ways to convert a datetime to ISO 8601 string including relevant examples and helper functions for complex patterns\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/code-maze.com\/convert-datetime-to-iso-8601-string-csharp\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Convert DateTime to ISO 8601 String in C# - Code Maze\" \/>\n<meta property=\"og:description\" content=\"Explain various ways to convert a datetime to ISO 8601 string including relevant examples and helper functions for complex patterns\" \/>\n<meta property=\"og:url\" content=\"https:\/\/code-maze.com\/convert-datetime-to-iso-8601-string-csharp\/\" \/>\n<meta property=\"og:site_name\" content=\"Code Maze\" \/>\n<meta property=\"article:published_time\" content=\"2022-01-20T06:00:52+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2024-02-01T14:34:16+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/code-maze.com\/wp-content\/uploads\/2021\/12\/social-csharp.png\" \/>\n\t<meta property=\"og:image:width\" content=\"1100\" \/>\n\t<meta property=\"og:image:height\" content=\"620\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/png\" \/>\n<meta name=\"author\" content=\"Ahsan Ullah\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@CodeMazeBlog\" \/>\n<meta name=\"twitter:site\" content=\"@CodeMazeBlog\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Ahsan Ullah\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"6 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":[\"Article\",\"BlogPosting\"],\"@id\":\"https:\/\/code-maze.com\/convert-datetime-to-iso-8601-string-csharp\/#article\",\"isPartOf\":{\"@id\":\"https:\/\/code-maze.com\/convert-datetime-to-iso-8601-string-csharp\/\"},\"author\":{\"name\":\"Ahsan Ullah\",\"@id\":\"https:\/\/code-maze.com\/#\/schema\/person\/90ad30bf08ba4a2ee4d4489a005da7e0\"},\"headline\":\"Convert DateTime to ISO 8601 String in C#\",\"datePublished\":\"2022-01-20T06:00:52+00:00\",\"dateModified\":\"2024-02-01T14:34:16+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\/\/code-maze.com\/convert-datetime-to-iso-8601-string-csharp\/\"},\"wordCount\":935,\"commentCount\":0,\"publisher\":{\"@id\":\"https:\/\/code-maze.com\/#organization\"},\"image\":{\"@id\":\"https:\/\/code-maze.com\/convert-datetime-to-iso-8601-string-csharp\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/code-maze.com\/wp-content\/uploads\/2021\/12\/social-csharp.png\",\"keywords\":[\".NET\",\"DateTime\",\"ISO 8691\",\"String\"],\"articleSection\":[\"C#\",\"DateTime\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\/\/code-maze.com\/convert-datetime-to-iso-8601-string-csharp\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\/\/code-maze.com\/convert-datetime-to-iso-8601-string-csharp\/\",\"url\":\"https:\/\/code-maze.com\/convert-datetime-to-iso-8601-string-csharp\/\",\"name\":\"Convert DateTime to ISO 8601 String in C# - Code Maze\",\"isPartOf\":{\"@id\":\"https:\/\/code-maze.com\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\/\/code-maze.com\/convert-datetime-to-iso-8601-string-csharp\/#primaryimage\"},\"image\":{\"@id\":\"https:\/\/code-maze.com\/convert-datetime-to-iso-8601-string-csharp\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/code-maze.com\/wp-content\/uploads\/2021\/12\/social-csharp.png\",\"datePublished\":\"2022-01-20T06:00:52+00:00\",\"dateModified\":\"2024-02-01T14:34:16+00:00\",\"description\":\"Explain various ways to convert a datetime to ISO 8601 string including relevant examples and helper functions for complex patterns\",\"breadcrumb\":{\"@id\":\"https:\/\/code-maze.com\/convert-datetime-to-iso-8601-string-csharp\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/code-maze.com\/convert-datetime-to-iso-8601-string-csharp\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/code-maze.com\/convert-datetime-to-iso-8601-string-csharp\/#primaryimage\",\"url\":\"https:\/\/code-maze.com\/wp-content\/uploads\/2021\/12\/social-csharp.png\",\"contentUrl\":\"https:\/\/code-maze.com\/wp-content\/uploads\/2021\/12\/social-csharp.png\",\"width\":1100,\"height\":620,\"caption\":\"C# Development\"},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/code-maze.com\/convert-datetime-to-iso-8601-string-csharp\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/code-maze.com\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Convert DateTime to ISO 8601 String in C#\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/code-maze.com\/#website\",\"url\":\"https:\/\/code-maze.com\/\",\"name\":\"Code Maze\",\"description\":\"Learn. Code. Succeed.\",\"publisher\":{\"@id\":\"https:\/\/code-maze.com\/#organization\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/code-maze.com\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Organization\",\"@id\":\"https:\/\/code-maze.com\/#organization\",\"name\":\"Code Maze\",\"url\":\"https:\/\/code-maze.com\/\",\"logo\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/code-maze.com\/#\/schema\/logo\/image\/\",\"url\":\"https:\/\/code-maze.com\/wp-content\/uploads\/2020\/01\/Code-Maze-Only-Logo-Transparent-HRez.png\",\"contentUrl\":\"https:\/\/code-maze.com\/wp-content\/uploads\/2020\/01\/Code-Maze-Only-Logo-Transparent-HRez.png\",\"width\":3511,\"height\":3510,\"caption\":\"Code Maze\"},\"image\":{\"@id\":\"https:\/\/code-maze.com\/#\/schema\/logo\/image\/\"},\"sameAs\":[\"https:\/\/x.com\/CodeMazeBlog\"]},{\"@type\":\"Person\",\"@id\":\"https:\/\/code-maze.com\/#\/schema\/person\/90ad30bf08ba4a2ee4d4489a005da7e0\",\"name\":\"Ahsan Ullah\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/code-maze.com\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/code-maze.com\/wp-content\/uploads\/2023\/12\/ahsan-ullah-profile-150x150.jpeg\",\"contentUrl\":\"https:\/\/code-maze.com\/wp-content\/uploads\/2023\/12\/ahsan-ullah-profile-150x150.jpeg\",\"caption\":\"Ahsan Ullah\"},\"description\":\"A Senior IT Developer with demonstrated proficiency (10+ years of experience) in supply chain management software projects of DSV A\/S. Senior member of the core development team helping to meet growing business demands. Competent in the .NET platform and Angular applications. Other expertise includes skills in database development, designing algorithms, and developing interfaces from low-level responsive html tools to high-level middleware services.\",\"sameAs\":[\"https:\/\/www.linkedin.com\/in\/md-ahsan-ullah-665aa7215\/\"],\"url\":\"https:\/\/code-maze.com\/author\/aullah\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Convert DateTime to ISO 8601 String in C# - Code Maze","description":"Explain various ways to convert a datetime to ISO 8601 string including relevant examples and helper functions for complex patterns","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/code-maze.com\/convert-datetime-to-iso-8601-string-csharp\/","og_locale":"en_US","og_type":"article","og_title":"Convert DateTime to ISO 8601 String in C# - Code Maze","og_description":"Explain various ways to convert a datetime to ISO 8601 string including relevant examples and helper functions for complex patterns","og_url":"https:\/\/code-maze.com\/convert-datetime-to-iso-8601-string-csharp\/","og_site_name":"Code Maze","article_published_time":"2022-01-20T06:00:52+00:00","article_modified_time":"2024-02-01T14:34:16+00:00","og_image":[{"width":1100,"height":620,"url":"https:\/\/code-maze.com\/wp-content\/uploads\/2021\/12\/social-csharp.png","type":"image\/png"}],"author":"Ahsan Ullah","twitter_card":"summary_large_image","twitter_creator":"@CodeMazeBlog","twitter_site":"@CodeMazeBlog","twitter_misc":{"Written by":"Ahsan Ullah","Est. reading time":"6 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":["Article","BlogPosting"],"@id":"https:\/\/code-maze.com\/convert-datetime-to-iso-8601-string-csharp\/#article","isPartOf":{"@id":"https:\/\/code-maze.com\/convert-datetime-to-iso-8601-string-csharp\/"},"author":{"name":"Ahsan Ullah","@id":"https:\/\/code-maze.com\/#\/schema\/person\/90ad30bf08ba4a2ee4d4489a005da7e0"},"headline":"Convert DateTime to ISO 8601 String in C#","datePublished":"2022-01-20T06:00:52+00:00","dateModified":"2024-02-01T14:34:16+00:00","mainEntityOfPage":{"@id":"https:\/\/code-maze.com\/convert-datetime-to-iso-8601-string-csharp\/"},"wordCount":935,"commentCount":0,"publisher":{"@id":"https:\/\/code-maze.com\/#organization"},"image":{"@id":"https:\/\/code-maze.com\/convert-datetime-to-iso-8601-string-csharp\/#primaryimage"},"thumbnailUrl":"https:\/\/code-maze.com\/wp-content\/uploads\/2021\/12\/social-csharp.png","keywords":[".NET","DateTime","ISO 8691","String"],"articleSection":["C#","DateTime"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/code-maze.com\/convert-datetime-to-iso-8601-string-csharp\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/code-maze.com\/convert-datetime-to-iso-8601-string-csharp\/","url":"https:\/\/code-maze.com\/convert-datetime-to-iso-8601-string-csharp\/","name":"Convert DateTime to ISO 8601 String in C# - Code Maze","isPartOf":{"@id":"https:\/\/code-maze.com\/#website"},"primaryImageOfPage":{"@id":"https:\/\/code-maze.com\/convert-datetime-to-iso-8601-string-csharp\/#primaryimage"},"image":{"@id":"https:\/\/code-maze.com\/convert-datetime-to-iso-8601-string-csharp\/#primaryimage"},"thumbnailUrl":"https:\/\/code-maze.com\/wp-content\/uploads\/2021\/12\/social-csharp.png","datePublished":"2022-01-20T06:00:52+00:00","dateModified":"2024-02-01T14:34:16+00:00","description":"Explain various ways to convert a datetime to ISO 8601 string including relevant examples and helper functions for complex patterns","breadcrumb":{"@id":"https:\/\/code-maze.com\/convert-datetime-to-iso-8601-string-csharp\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/code-maze.com\/convert-datetime-to-iso-8601-string-csharp\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/code-maze.com\/convert-datetime-to-iso-8601-string-csharp\/#primaryimage","url":"https:\/\/code-maze.com\/wp-content\/uploads\/2021\/12\/social-csharp.png","contentUrl":"https:\/\/code-maze.com\/wp-content\/uploads\/2021\/12\/social-csharp.png","width":1100,"height":620,"caption":"C# Development"},{"@type":"BreadcrumbList","@id":"https:\/\/code-maze.com\/convert-datetime-to-iso-8601-string-csharp\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/code-maze.com\/"},{"@type":"ListItem","position":2,"name":"Convert DateTime to ISO 8601 String in C#"}]},{"@type":"WebSite","@id":"https:\/\/code-maze.com\/#website","url":"https:\/\/code-maze.com\/","name":"Code Maze","description":"Learn. Code. Succeed.","publisher":{"@id":"https:\/\/code-maze.com\/#organization"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/code-maze.com\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Organization","@id":"https:\/\/code-maze.com\/#organization","name":"Code Maze","url":"https:\/\/code-maze.com\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/code-maze.com\/#\/schema\/logo\/image\/","url":"https:\/\/code-maze.com\/wp-content\/uploads\/2020\/01\/Code-Maze-Only-Logo-Transparent-HRez.png","contentUrl":"https:\/\/code-maze.com\/wp-content\/uploads\/2020\/01\/Code-Maze-Only-Logo-Transparent-HRez.png","width":3511,"height":3510,"caption":"Code Maze"},"image":{"@id":"https:\/\/code-maze.com\/#\/schema\/logo\/image\/"},"sameAs":["https:\/\/x.com\/CodeMazeBlog"]},{"@type":"Person","@id":"https:\/\/code-maze.com\/#\/schema\/person\/90ad30bf08ba4a2ee4d4489a005da7e0","name":"Ahsan Ullah","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/code-maze.com\/#\/schema\/person\/image\/","url":"https:\/\/code-maze.com\/wp-content\/uploads\/2023\/12\/ahsan-ullah-profile-150x150.jpeg","contentUrl":"https:\/\/code-maze.com\/wp-content\/uploads\/2023\/12\/ahsan-ullah-profile-150x150.jpeg","caption":"Ahsan Ullah"},"description":"A Senior IT Developer with demonstrated proficiency (10+ years of experience) in supply chain management software projects of DSV A\/S. Senior member of the core development team helping to meet growing business demands. Competent in the .NET platform and Angular applications. Other expertise includes skills in database development, designing algorithms, and developing interfaces from low-level responsive html tools to high-level middleware services.","sameAs":["https:\/\/www.linkedin.com\/in\/md-ahsan-ullah-665aa7215\/"],"url":"https:\/\/code-maze.com\/author\/aullah\/"}]}},"_links":{"self":[{"href":"https:\/\/code-maze.com\/wp-json\/wp\/v2\/posts\/63713","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/code-maze.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/code-maze.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/code-maze.com\/wp-json\/wp\/v2\/users\/38"}],"replies":[{"embeddable":true,"href":"https:\/\/code-maze.com\/wp-json\/wp\/v2\/comments?post=63713"}],"version-history":[{"count":4,"href":"https:\/\/code-maze.com\/wp-json\/wp\/v2\/posts\/63713\/revisions"}],"predecessor-version":[{"id":63771,"href":"https:\/\/code-maze.com\/wp-json\/wp\/v2\/posts\/63713\/revisions\/63771"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/code-maze.com\/wp-json\/wp\/v2\/media\/62189"}],"wp:attachment":[{"href":"https:\/\/code-maze.com\/wp-json\/wp\/v2\/media?parent=63713"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/code-maze.com\/wp-json\/wp\/v2\/categories?post=63713"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/code-maze.com\/wp-json\/wp\/v2\/tags?post=63713"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}