Android Context Get getCurrentTimeString(Context aContext, long aDate)

Here you can find the source of getCurrentTimeString(Context aContext, long aDate)

Description

Gets current date in string representation

Parameter

Parameter Description
aContext Context
aDate Current date

Return

Current date

Declaration

public static String getCurrentTimeString(Context aContext, long aDate) 

Method Source Code

//package com.java2s;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.TimeZone;
import android.content.Context;
import android.text.format.DateFormat;

public class Main {
    /**/*from   ww w  .  j a  va2 s.  c  o  m*/
     * Gets current date in string representation
     * 
     * @param aContext
     *            Context
     * @param aDate
     *            Current date
     * @return Current date
     */
    public static String getCurrentTimeString(Context aContext, long aDate) {
        String pattern = "";
        if (DateFormat.is24HourFormat(aContext)) {
            pattern = "dd-MM-yyyy  HH:mm";
        } else {
            pattern = "dd-MM-yyyy  hh:mm a";
        }
        Calendar calendar = Calendar.getInstance(TimeZone
                .getTimeZone("UTC"));
        calendar.setTimeInMillis(aDate);

        SimpleDateFormat formatter = new SimpleDateFormat(pattern);
        formatter.setTimeZone(TimeZone.getDefault());
        String result = formatter.format(calendar.getTimeInMillis());
        return result;
    }
}

Related

  1. getString(Context context, int id)
  2. getString(Context context, int resId, Map replacement)
  3. getStringFromXml(Context context, int resId)
  4. getBoolean(ContentValues alarm, String key)
  5. findOne(Context context, Uri uri)
  6. getCurrentTimeString(Context context)
  7. readRaw(Context ctx, int res_id)
  8. loadImageFromAsset(Context context, String id)
  9. hasTelephony(@Nonnull Context context)