回答:
標準のJava DateFormatクラスを使用します。
たとえば、現在の日付と時刻を表示するには、次のようにします。
Date date = new Date(location.getTime());
DateFormat dateFormat = android.text.format.DateFormat.getDateFormat(getApplicationContext());
mTimeText.setText("Time: " + dateFormat.format(date));
独自の値でDateオブジェクトを初期化できますが、コンストラクターが非推奨になり、実際にはJava Calendarオブジェクトを使用する必要があることに注意してください。
DateFormat dateFormat = android.text.format.DateFormat.getDateFormat(getApplicationContext());返されるdateFormatのタイプはjava.text.DateFormat(そしてNOTですandroid.text.format.DateFormat)
                    私の意見でandroid.text.format.DateFormat.getDateFormat(context)は、このメソッドは--"ではjava.text.DateFormatなく戻るため、混乱しますandroid.text.format.DateFormat。
したがって、以下のフラグメントコードを使用して、現在の日付/時刻を自分の形式で取得します。
android.text.format.DateFormat df = new android.text.format.DateFormat();
df.format("yyyy-MM-dd hh:mm:ss a", new java.util.Date());
or
android.text.format.DateFormat.format("yyyy-MM-dd hh:mm:ss a", new java.util.Date());
さらに、他の形式を使用できます。DateFormatに従ってください。
hh:mm:ssなることを忘れない01:00:00でください。kk:mm:ss取得するには、13:00:00
                    kは1日の時間(1〜24)ですH。つまり、は1日の時間(0〜23)です。HH:mm:ss?参照:developer.android.com/reference/java/text/SimpleDateFormat.html
                    java.text.SimpleDateFormat(あなたがリンクされ、どのような用途Hと0-23の範囲内の時間)android.text.format.DateFormat(答えはあるものについておよび使用k0-23の範囲内の時間)
                    k、ドキュメントにはDateFormat明確に述べられていますフォーマット文字列の正規のドキュメントについては、SimpleDateFormatを参照してください。  とても紛らわしい。それとも何か不足していますか?
                    使用できますDateFormat。結果は電話のデフォルトのロケールによって異なりますが、ロケールも指定できます。
https://developer.android.com/reference/java/text/DateFormat.html
これは
DateFormat.getDateInstance().format(date)                                          
FRロケール:11月3日 2017年
US / Enロケール:1952年1月12日
DateFormat.getDateInstance(DateFormat.SHORT).format(date)
FRロケール:2017年3月11日
US / Enロケール:12.13.52
DateFormat.getDateInstance(DateFormat.MEDIUM).format(date)
FRロケール:11月3日 2017年
US / Enロケール:1952年1月12日
DateFormat.getDateInstance(DateFormat.LONG).format(date)
FRロケール:2017年11月3日
US / Enロケール:1952年1月12日
DateFormat.getDateInstance(DateFormat.FULL).format(date)
FRロケール:vendredi 2017年11月3日
US / Enロケール:1952年4月12日火曜日
DateFormat.getDateTimeInstance().format(date)
FRロケール:11月3日 2017 16:04:58
DateFormat.getDateTimeInstance(DateFormat.SHORT, DateFormat.SHORT).format(date)
FRロケール:2017年11月3日16:04
DateFormat.getDateTimeInstance(DateFormat.SHORT, DateFormat.MEDIUM).format(date)
FRロケール:2017年11月3日16:04:58
DateFormat.getDateTimeInstance(DateFormat.SHORT, DateFormat.LONG).format(date)
FRロケール:2017年11月3日16:04:58 GMT + 01:00
DateFormat.getDateTimeInstance(DateFormat.SHORT, DateFormat.FULL).format(date)
FRロケール:2017年3月11日16:04:58中央ヨーロッパ中央
DateFormat.getTimeInstance().format(date)
FRロケール:16:04:58
DateFormat.getTimeInstance(DateFormat.SHORT).format(date)
FRロケール:16:04
DateFormat.getTimeInstance(DateFormat.MEDIUM).format(date)
FRロケール:16:04:58
DateFormat.getTimeInstance(DateFormat.LONG).format(date)
FRロケール:16:04:58 GMT + 01:00
DateFormat.getTimeInstance(DateFormat.FULL).format(date)
FRロケール:16:04:58 heure normale d'Europe centrale
日付からロケールへの日付文字列:
Date date = new Date();
String stringDate = DateFormat.getDateTimeInstance().format(date);
オプション:
   DateFormat.getDateInstance() 
-> 1969年12月31日
   DateFormat.getDateTimeInstance() 
-> 1969年12月31日4:00:00 PM
   DateFormat.getTimeInstance() 
->午後4:00:00
これはそれを行います:
Date date = new Date();
java.text.DateFormat dateFormat = android.text.format.DateFormat.getDateFormat(getApplicationContext());
mTimeText.setText("Time: " + dateFormat.format(date));
              SimpleDateFormatを使用する
このような:
event.putExtra("starttime", "12/18/2012");
SimpleDateFormat format = new SimpleDateFormat("MM/dd/yyyy");
Date date = format.parse(bundle.getString("starttime"));
              new SimpleDateFormat("my-format", Locale.getDefault());
                    これに続いて:http : //developer.android.com/reference/android/text/format/Time.html
AndroidネイティブのTimeクラスを使用することをお勧めします。
Time now = new Time();
now.setToNow();
次にフォーマット:
Log.d("DEBUG", "Time "+now.format("%d.%m.%Y %H.%M.%S"));
              これら2つをクラス変数として使用します。
 public java.text.DateFormat dateFormat = new SimpleDateFormat("dd/MM/yyyy");
 private Calendar mDate = null;
次のように使用します。
 mDate = Calendar.getInstance();
 mDate.set(year,months,day);                   
 dateFormat.format(mDate.getTime());
              これは私の方法であり、入力形式と出力形式を定義して入力できます。
public static String formattedDateFromString(String inputFormat, String outputFormat, String inputDate){
    if(inputFormat.equals("")){ // if inputFormat = "", set a default input format.
        inputFormat = "yyyy-MM-dd hh:mm:ss";
    }
    if(outputFormat.equals("")){
        outputFormat = "EEEE d 'de' MMMM 'del' yyyy"; // if inputFormat = "", set a default output format.
    }
    Date parsed = null;
    String outputDate = "";
    SimpleDateFormat df_input = new SimpleDateFormat(inputFormat, java.util.Locale.getDefault());
    SimpleDateFormat df_output = new SimpleDateFormat(outputFormat, java.util.Locale.getDefault());
    // You can set a different Locale, This example set a locale of Country Mexico.
    //SimpleDateFormat df_input = new SimpleDateFormat(inputFormat, new Locale("es", "MX"));
    //SimpleDateFormat df_output = new SimpleDateFormat(outputFormat, new Locale("es", "MX"));
    try {
        parsed = df_input.parse(inputDate);
        outputDate = df_output.format(parsed);
    } catch (Exception e) { 
        Log.e("formattedDateFromString", "Exception in formateDateFromstring(): " + e.getMessage());
    }
    return outputDate;
}
              Build in Timeクラスを使用してください!
Time time = new Time();
time.set(0, 0, 17, 4, 5, 1999);
Log.i("DateTime", time.format("%d.%m.%Y %H:%M:%S"));
              他の答えは一般的に正しいです。私は現代の答えに貢献したいと思います。クラスDate、DateFormatおよびSimpleDateFormat他の回答のほとんどに使用されるが、長い時代遅れであり、長年にわたり多くのプログラマのためのトラブルを引き起こしています。今日ではjava.time、JSR-310と呼ばれる最新のJava日付および時刻APIが大幅に向上しています。これをAndroidでまだ使用できますか?間違いなく!最新のクラスは、ThreeTenABPプロジェクトでAndroidにバックポートされています。この質問を参照してください:AndroidプロジェクトでThreeTenABPを使用する方法で。
このスニペットはあなたを始めるでしょう:
    int year = 2017, month = 9, day = 28, hour = 22, minute = 45;
    LocalDateTime dateTime = LocalDateTime.of(year, month, day, hour, minute);
    DateTimeFormatter formatter = DateTimeFormatter.ofLocalizedDateTime(FormatStyle.MEDIUM);
    System.out.println(dateTime.format(formatter));
コンピューターの優先言語を米国英語または英国英語に設定すると、次のように出力されます。
Sep 28, 2017 10:45:00 PM
代わりにデンマーク語に設定すると、次のようになります。
28-09-2017 22:45:00
したがって、構成に従います。ただし、デバイスの日付と時刻の設定がどのように続くかは正確にはわかりません。これは電話によって異なる場合があります。
このコードは私のために働きます!
Date d = new Date();
    CharSequence s = android.text.format.DateFormat.format("MM-dd-yy hh-mm-ss",d.getTime());
    Toast.makeText(this,s.toString(),Toast.LENGTH_SHORT).show();
              ミリ秒からロケール形式で日付または時刻を取得するには、これを使用しました:
Date date = new Date(milliseconds);
DateFormat dateFormat = DateFormat.getDateTimeInstance(DateFormat.MEDIUM, DateFormat.SHORT, Locale.getDefault());
dateFormat.format(date);
Date date = new Date(milliseconds);
DateFormat dateFormat = DateFormat.getDateInstance(DateFormat.MEDIUM, Locale.getDefault());
dateFormat.format(date);
Date date = new Date(milliseconds);
DateFormat dateFormat = DateFormat.getTimeInstance(DateFormat.SHORT, Locale.getDefault());
dateFormat.format(date);
他の日付スタイルと時間スタイルを使用できます。スタイルの詳細については、こちらをご覧ください。
最短の方法:
// 2019-03-29 16:11
String.format("%1$tY-%<tm-%<td %<tR", Calendar.getInstance())
%tRはの略で%tH:%tM、<最後のパラメータ(1$)を再利用することを意味します。
に相当します String.format("%1$tY-%1$tm-%1$td %1$tH:%1$tM", Calendar.getInstance())
https://developer.android.com/reference/java/util/Formatter.html
試してください:
event.putExtra("startTime", "10/05/2012");
渡された変数にアクセスしている場合:
SimpleDateFormat formatter = new SimpleDateFormat("dd/MM/yyyy");
Date date = formatter.parse(bundle.getString("startTime"));
              私はそれを次のように使用します:
public class DateUtils {
    static DateUtils instance;
    private final DateFormat dateFormat;
    private final DateFormat timeFormat;
    private DateUtils() {
        dateFormat = android.text.format.DateFormat.getDateFormat(MainApplication.context);
        timeFormat = android.text.format.DateFormat.getTimeFormat(MainApplication.context);
    }
    public static DateUtils getInstance() {
        if (instance == null) {
            instance = new DateUtils();
        }
        return instance;
    }
    public synchronized static String formatDateTime(long timestamp) {
        long milliseconds = timestamp * 1000;
        Date dateTime = new Date(milliseconds);
        String date = getInstance().dateFormat.format(dateTime);
        String time = getInstance().timeFormat.format(dateTime);
        return date + " " + time;
    }
}
              Java(およびAndroid)でのJava.util.Dateと.CalendarおよびSimpleDateFormatは、非常に面倒です。それらを避けてください。それらは非常に悪いため、Sun / Oracleはあきらめ、Java 8の新しいjava.timeパッケージ(2014年の時点ではAndroidではありません)に取って代わりました。新しいものjava.timeは、Joda-Timeライブラリに触発されました。
Joda-TimeはAndroidで動作します。
StackOverflowで「Joda」を検索して、多くの例と多くの議論を見つけてください。
Joda-Time 2.4を使用したソースコードの一口。
標準フォーマット。
String output = DateTime.now().toString(); 
// Current date-time in user's default time zone with a String representation formatted to the ISO 8601 standard.
ローカライズされた形式。
String output = DateTimeFormat.forStyle( "FF" ).print( DateTime.now() ); 
// Full (long) format localized for this user's language and culture.
              2016年に戻って、形式をカスタマイズしたい場合(デバイスの構成に応じてではなく、質問どおり...)通常は文字列リソースファイルを使用します。
strings.xml内:
<string name="myDateFormat"><xliff:g id="myDateFormat">%1$td/%1$tm/%1$tY</xliff:g></string>
活動中:
Log.d(TAG, "my custom date format: "+getString(R.string.myDateFormat, new Date()));
これは、新しい日付バインディングライブラリのリリースでも役立ちます。
だから私はレイアウトファイルでこのようなものを持つことができます:
<TextView
    android:id="@+id/text_release_date"
    android:layout_width="wrap_content"
    android:layout_height="0dp"
    android:layout_weight="1"
    android:padding="2dp"
    android:text="@{@string/myDateFormat(vm.releaseDate)}"
    tools:text="0000"
    />
そしてJavaクラスでは:
    MovieDetailViewModel vm = new MovieDetailViewModel();
    vm.setReleaseDate(new Date());
              android Timeクラスは3つのフォーマットメソッドを提供しますhttp://developer.android.com/reference/android/text/format/Time.html
これは私がそれをした方法です:
/**
* This method will format the data from the android Time class (eg. myTime.setToNow())   into the format
* Date: dd.mm.yy Time: hh.mm.ss
*/
private String formatTime(String time)
{
    String fullTime= "";
    String[] sa = new String[2];
    if(time.length()>1)
    {
        Time t = new Time(Time.getCurrentTimezone());
        t.parse(time);
        // or t.setToNow();
        String formattedTime = t.format("%d.%m.%Y %H.%M.%S");
        int x = 0;
        for(String s : formattedTime.split("\\s",2))
        {   
            System.out.println("Value = " + s);
            sa[x] = s;
            x++;
        }
        fullTime = "Date: " + sa[0] + " Time: " + sa[1];
    }
    else{
        fullTime = "No time data";
    }
    return fullTime;
}
お役に立てば幸いです:-)
手遅れですが、誰かに役立つかもしれません
DateFormat.format(format, timeInMillis);
ここにformatあなたが必要なフォーマットがあります
例:「HH:mm」は15:30を返します