NGWS SDK Documentation  

This is preliminary documentation and subject to change.
To comment on this topic, please send us email at ngwssdk@microsoft.com. Thanks!

DateTime.Format

Converts this DateTime to a String with the specified format string and IServiceObjectProvider.

[Visual Basic]
Overridable Public Function Format( _
   ByVal format As String, _
   ByVal sp As IServiceObjectProvider _
) As String
[C#]
public virtual string Format(
   string format,
   IServiceObjectProvider sp
);
[C++]
public: virtual String* Format(
   String* format,
   IServiceObjectProvider* sp
);
[JScript]
public function Format(
   format : String,
   sp : IServiceObjectProvider
) : String;

Parameters

format
The format string.
sp
The IServiceObjectProvider instance used to format this DateTime value.

Return Value

A string representation of DateTime in the format specified by format.

Remarks

The format parmeter should consist of either:

If this argument is null or an empty string, the standard format ('g') character is used.

The sp parameter is typically an instance of DateTimeFormatInfo. If this value is null, the DateTimeFormatInfo object associated with the CultureInfo of the current thread is used.

Example

The following Managed C++ sample demonstrates how DateTime values are formatted with the invariant DateTimeFormatInfo object.

#import
<mscorlib.dll>
 
void
main ()
{
  DateTime dt = DateTime::Now;
 
  __managed String * [] format= {
   L"d",
   L"D",
   L"f",
   L"F",
   L"g",
   L"G",
   L"m",
   L"r",
   L"s",
   L"S",
   L"t",
   L"T",
   L"u",
   L"U",
   L"y",
   L"dddd, MMMM dd yyyy",
   L"ddd, MMM d \"'\"yy",
   L"dddd, MMMM dd",
   L"M/yy",
   L"dd-MM-yy",
  };
  String * date;
  for (int i = 0; i < format->Length;
i++)
  {
    date = dt.Format(format[i],
DateTimeFormatInfo::GetInvariantInfo());
    Console::WriteLine(format[i] + L" :
" + date);
  }
 
  /** OUTPUT
   *
   * d : 07/17/1999
   * D : Saturday, July 17, 1999
   * f : Saturday, July 17, 1999 23:17
   * F : Saturday, July 17, 1999 23:17:19
   * g : 07/17/1999 23:17
   * G : 07/17/1999 23:17:19
   * m : July 17
   * r : Sun, 18 Jul 1999 06:17:19 GMT
   * s : 1999-07-17 23:17:19
   * S : S
   * t : 23:17
   * T : 23:17:19
   * u : 1999-07-18 06:17:19
   * U : Sunday, July 18, 1999 06:17:19
   * y : July, 1999
   * dddd, MMMM dd yyyy : Thursday, July 22
1999
   * ddd, MMM d "'"yy : Thu, Jul 22
'99
   * dddd, MMMM dd : Thursday, July 22
   * M/yy : 7/99
   * dd-MM-yy : 22-07-99
   */
}

See Also

DateTime Structure | DateTime Members | System Namespace | DateTimeFormatInfo | CultureInfo | String