C# RFC1123 ("R", "r") Format

In this chapter you will learn:

  1. How to use RFC1123 ("R", "r") Format Specifier
  2. Example to use RFC1123 ("R", "r") Format Specifier

Description

The "R" or "r" format is defined by the DateTimeFormatInfo.RFC1123Pattern property.

The custom format string is "ddd, dd MMM yyyy HH':'mm':'ss 'GMT'".

The following the DateTimeFormatInfo properties controls the format.

  • RFC1123Pattern
  • AbbreviatedDayNames
  • AbbreviatedMonthNames

The application must convert the date and time value to UTC before it performs the formatting operation. To perform this conversion, DateTime values can call the DateTime.ToUniversalTime method, and DateTimeOffset values can call the ToUniversalTime method.

Example

The following example uses the "r" format specifier to display a DateTime and a DateTimeOffset value on a system in the U.S. Pacific Time zone.


// ww  w  .  ja v a  2  s  .c  o m
using System;

class MainClass
{

  public static void Main()
  {
        DateTime date1 = new DateTime(2008, 4, 10, 6, 30, 0);
        DateTimeOffset dateOffset = new DateTimeOffset(date1, 
                                    TimeZoneInfo.Local.GetUtcOffset(date1));
        Console.WriteLine(date1.ToUniversalTime().ToString("r"));
        // Displays Thu, 10 Apr 2008 13:30:00 GMT                       
        Console.WriteLine(dateOffset.ToUniversalTime().ToString("r"));
        // Displays Thu, 10 Apr 2008 13:30:00 GMT     

  }

}

The code above generates the following result.

Next chapter...

What you will learn in the next chapter:

  1. How to use Universal Full ("U") Format Specifier
  2. Example to use Universal Full ("U") Format Specifier
Home »
  C# Tutorial »
    C# Language »
      C# Date Time Format
C# Standard Date Time Formatter
C# Full Date Long Time ("F") Format
C# Full Date Short Time ("f") Format
C# General Date Long Time ("G") Format
C# General Date Short Time ("g") Format
C# Long Date ("D") Format
C# Long Time ("T") Format
C# Short Date ("d") Format
C# Short Time ("t") Format
C# Month ("M", "m") Format
C# Year Month ("Y", "y") Format
C# RFC1123 ("R", "r") Format
C# Universal Full ("U") Format
C# Universal Sortable ("u") Format
C# Round-trip ("O", "o") Format
C# Sortable ("s") Format