Return a timestamp - Android java.util

Android examples for java.util:Date Timestamp

Description

Return a timestamp

Demo Code

import java.util.Date;

import android.content.Context;

public class Main {
  /**// ww w  . ja  va  2 s  .  com
   * Return a timestamp
   *
   * @param context
   *          Application Context
   */
  public static String getTimestamp(final Context context) {
    String timestamp;
    timestamp = "unknown";
    Date now = new Date();
    java.text.DateFormat dateFormat = android.text.format.DateFormat.getDateFormat(context);
    java.text.DateFormat timeFormat = android.text.format.DateFormat.getTimeFormat(context);
    if (dateFormat != null && timeFormat != null) {
      timestamp = dateFormat.format(now) + " " + timeFormat.format(now);
    }
    return timestamp;
  }
}

Related Tutorials