MailBee.NET Objects 4.0

ImapUtils.GetImapDateTimeString Method (DateTime, Boolean, String)

Returns the string containing the specified date and time value in the IMAP4 format.

public static string GetImapDateTimeString(
   DateTime dt,
   bool includeTime,
   string timeZoneOffset
);

Parameters

dt
The date and time.
includeTime
If true, the date, time, and timezone will be included into the resulting string; otherwise, only the date will be included.
timeZoneOffset
The timezone string in "+/-HHmm" format, or a null reference (Nothing in Visual Basic) if no timezone should be specified. Ignored if includeTime is false.

Return Value

The IMAP4 datetime string in "dd-MMM-yyyy HH:mm:ss +/-HHmm", "dd-MMM-yyyy HH:mm:ss", or "dd-MMM-yyyy" format.

Remarks

When uploading messages with UploadMessage method, the datetime value can contain all 3 fields (date, time, and timezone). When searching messages with Search method, datetime values can contain only date field.

Example

This sample prints certain DateTime value as IMAP4-formatted string.

[C#]
using System;
using MailBee;
using MailBee.ImapMail;

class Sample
{
    static void Main(string[] args)
    {
        // Assume it's 8 Apr 2006 14:45:50 (24 hrs clock) now,
        // and the local timezone is EDT (UTC minus 4 hrs 0 mins).
        DateTime dt = DateTime.Now;

        Console.WriteLine(ImapUtils.GetImapDateTimeString(dt, true, "-0400"));
        // The output: 08-Apr-2006 14:45:50 -0400

        Console.WriteLine(ImapUtils.GetImapDateTimeString(dt, false, "-0400"));
        // The output: 08-Apr-2006

        Console.WriteLine(ImapUtils.GetImapDateTimeString(dt, true, null));
        // The output: 08-Apr-2006 14:45:50
    }
}
[Visual Basic]
Imports System
Imports MailBee
Imports MailBee.ImapMail

Module Sample
    Sub Main(ByVal args As String())
        ' Assume it's 8 Apr 2006 14:45:50 (24 hrs clock) now,
        ' and the local timezone is EDT (UTC minus 4 hrs 0 mins).

        Dim dt As DateTime = DateTime.Now

        Console.WriteLine(ImapUtils.GetImapDateTimeString(dt, True, "-0400"))
        ' The output: 08-Apr-2006 14:45:50 -0400

        Console.WriteLine(ImapUtils.GetImapDateTimeString(dt, False, "-0400"))
        ' The output: 08-Apr-2006

        Console.WriteLine(ImapUtils.GetImapDateTimeString(dt, True, CType(Nothing, String)))
        ' The output: 08-Apr-2006 14:45:50
    End Sub
End Module

See Also

ImapUtils Class | MailBee.ImapMail Namespace | ImapUtils.GetImapDateTimeString Overload List