DateTimeOffset.Month Propiedad

Definición

Obtiene el componente de mes de la fecha representada por el objeto DateTimeOffset actual.

public:
 property int Month { int get(); };
public int Month { get; }
member this.Month : int
Public ReadOnly Property Month As Integer

Valor de propiedad

Componente de mes del objeto DateTimeOffset actual, expresado como un entero entre 1 y 12.

Ejemplos

En el ejemplo siguiente se muestra el componente month de un DateTimeOffset valor de tres maneras diferentes:

  • Recuperando el valor de la Month propiedad .

  • Llamando al ToString(String) método con el especificador de formato "M".

  • Llamando al ToString(String) método con el especificador de formato "MM".

DateTimeOffset theTime = new DateTimeOffset(2008, 9, 7, 11, 25, 0,
                                       DateTimeOffset.Now.Offset);
Console.WriteLine("The month component of {0} is {1}.",
                  theTime, theTime.Month);

Console.WriteLine("The month component of {0} is{1}.",
                  theTime, theTime.ToString(" M"));

Console.WriteLine("The month component of {0} is {1}.",
                  theTime, theTime.ToString("MM"));
// The example produces the following output:
//    The month component of 9/7/2008 11:25:00 AM -08:00 is 9.
//    The month component of 9/7/2008 11:25:00 AM -08:00 is 9.
//    The month component of 9/7/2008 11:25:00 AM -08:00 is 09.
let theTime = DateTimeOffset(2008, 9, 7, 11, 25, 0, DateTimeOffset.Now.Offset)
printfn $"The month component of {theTime} is {theTime.Month}."

printfn $"""The month component of {theTime} is{theTime.ToString " M"}."""

printfn $"""The month component of {theTime} is {theTime.ToString "MM"}."""

// The example produces the following output:
//    The month component of 9/7/2008 11:25:00 AM -08:00 is 9.
//    The month component of 9/7/2008 11:25:00 AM -08:00 is 9.
//    The month component of 9/7/2008 11:25:00 AM -08:00 is 09.
Dim theTime As New DateTimeOffset(#9/7/2008 11:25AM#, _
                                       DateTimeOffset.Now.Offset)
Console.WriteLine("The month component of {0} is {1}.", _
                  theTime, theTime.Month)

Console.WriteLine("The month component of {0} is{1}.", _
                  theTime, theTime.ToString(" M"))

Console.WriteLine("The month component of {0} is {1}.", _
                  theTime, theTime.ToString("MM"))
' The example produces the following output:
'    The month component of 9/7/2008 11:25:00 AM -08:00 is 9.
'    The month component of 9/7/2008 11:25:00 AM -08:00 is 9.
'    The month component of 9/7/2008 11:25:00 AM -08:00 is 09.

Comentarios

La Month propiedad no se ve afectada por el valor de la Offset propiedad .

También puede crear una representación de cadena del componente month de un DateTimeOffset objeto llamando al ToString método con los especificadores de formato personalizado "M" o "MM".

Se aplica a