MailBee.NET Objects 4.0

ImapUtils.GetImapDateTimeString Method (DateTime, Boolean, Boolean)

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

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

Parameters

dt
The date and time in UTC or local timezone.
includeTime
If true, the date, time, and timezone will be included into the resulting string; otherwise, only the date will be included.
isUtc
Indicates if dt is UTC time or local time. 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 is true, the timezone part of the returned string will be "+0000"; otherwise, the local timezone in "+/-HHmm" format (such as "-0500" for EST). However, if includeTime is false, the time and timezone information will not be appended to the resulting string. "

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 UTC and local time versions of certain DateTime value as IMAP4-formatted strings.

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

class Sample
{
    static void Main(string[] args)
    {
        // Assume it's 31-Dec-2005 20:00:00 (24 hrs clock) now,
        // and the local timezone is EST (UTC minus 5 hrs 0 mins).
        DateTime dtLocal = DateTime.Now;
        DateTime dtUtc = dtLocal.ToUniversalTime();

        Console.WriteLine(ImapUtils.GetImapDateTimeString(dtLocal, true, false));
        // The output: 31-Dec-2005 20:00:00 -0500

        Console.WriteLine(ImapUtils.GetImapDateTimeString(dtUtc, true, true));
        // The output: 01-Jan-2006 01:00:00 +0000

        Console.WriteLine(ImapUtils.GetImapDateTimeString(dtLocal, false, false));
        // The output: 31-Dec-2005

        Console.WriteLine(ImapUtils.GetImapDateTimeString(dtUtc, false, true));
        // The output: 01-Jan-2006
    }
}
[Visual Basic]
Imports System
Imports MailBee
Imports MailBee.ImapMail

Module Sample
    Sub Main(ByVal args As String())
        ' Assume it's 31-Dec-2005 20:00:00 (24 hrs clock) now,
        ' and the local timezone is EST (UTC minus 5 hrs 0 mins).
        Dim dtLocal, dtUtc As DateTime

        dtLocal = DateTime.Now()
        dtUtc = dtLocal.ToUniversalTime()

        Console.WriteLine(ImapUtils.GetImapDateTimeString(dtLocal, True, False))
        ' The output: 31-Dec-2005 20:00:00 -0500

        Console.WriteLine(ImapUtils.GetImapDateTimeString(dtUtc, True, True))
        ' The output: 01-Jan-2006 01:00:00 +0000

        Console.WriteLine(ImapUtils.GetImapDateTimeString(dtLocal, False, False))
        ' The output: 31-Dec-2005

        Console.WriteLine(ImapUtils.GetImapDateTimeString(dtUtc, False, True))
        ' The output: 01-Jan-2006
    End Sub
End Module

See Also

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