Sample code for 30+ languages & platforms
Android™

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 Android™ Downloads

Android™
// Important: Don't forget to include the call to System.loadLibrary
// as shown at the bottom of this code sample.
package com.test;

import android.app.Activity;
import com.chilkatsoft.*;

import android.widget.TextView;
import android.os.Bundle;

public class SimpleActivity extends Activity {

  private static final String TAG = "Chilkat";

  // Called when the activity is first created.
  @Override
  public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    boolean success = false;

    CkMime mime = new CkMime();
    success = mime.SetBodyFromPlainText("Message with a Date header.");
    if (success == false) {
        Log.i(TAG, 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();
    Log.i(TAG, "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) {
        Log.i(TAG, mime.lastErrorText());
        return;
        }

    Log.i(TAG, head);

  }

  static {
      System.loadLibrary("chilkat");

      // Note: If the incorrect library name is passed to System.loadLibrary,
      // then you will see the following error message at application startup:
      //"The application <your-application-name> has stopped unexpectedly. Please try again."
  }
}