Sample code for 30+ languages & platforms
Java

MIME CurrentDateTime Property

See more MIME Examples

Demonstrates the read-only CurrentDateTime property, which returns the current local date and time formatted as an Internet message date including the numeric UTC offset. The example uses it to populate a Date header field.

Background. Internet message dates follow the RFC 5322 format, for example Fri, 21 Nov 1997 09:55:06 -0600. CurrentDateTime produces a value in that form for use in message headers.

Chilkat Java Downloads

Java
import com.chilkatsoft.*;

public class ChilkatExample {

  static {
    try {
        System.loadLibrary("chilkat");
    } catch (UnsatisfiedLinkError e) {
      System.err.println("Native code library failed to load.\n" + e);
      System.exit(1);
    }
  }

  public static void main(String argv[])
  {
    boolean success = false;

    CkMime mime = new CkMime();
    success = mime.SetBodyFromPlainText("Message with a Date header.");
    if (success == false) {
        System.out.println(mime.lastErrorText());
        return;
        }

    //  CurrentDateTime returns the current local date and time formatted as an Internet message date,
    //  including the numeric UTC offset, for example: Fri, 21 Nov 1997 09:55:06 -0600
    String now = mime.currentDateTime();
    System.out.println("Current date/time: " + now);

    //  It can be used to populate a Date header field.
    mime.SetHeaderField("Date",now);

    String head = mime.getEntireHead();
    if (mime.get_LastMethodSuccess() == false) {
        System.out.println(mime.lastErrorText());
        return;
        }

    System.out.println(head);
  }
}