0

この日付タイプ「Thu Feb 02 12:00:00 GMT-12:00 2012」を別の日付タイプ「yyyy-mm-dd HH:mm:ss」に変更するにはどうすればよいですか? 「Thu Feb 02 12:00:00 GMT-12:00 2012」が String 型の場合、「yyyy-MM-dd HH:mm:ss」の Date 型を変換するにはどうすればよいですか?

ジャバコード:

DateFormat inputDF = new SimpleDateFormat("EEE MMM dd HH:mm:ss Z yyyy");
   DateFormat outputDF = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
   Date dd = inputDF.parse("Thu Feb 02 12:00:00 GMT-12:00 2012");
   String strDate = outputDF.format(dd);

出力は文字列型です。Date 型の出力を取得したいので、次のコードを追加しました。

   Date outputDate = outputDF.parse(strDate);

しかし、この「EEE MMM dd HH:mm:ss Z yyyy」形式で再び日付を取得します。この「yyyy-MM-dd HH:mm:ss」形式で日付を取得し、日付タイプも必要です。

また、出力タイプを日付型形式にしたいと考えています。

4

5 に答える 5

2
DateFormat inputDF = new SimpleDateFormat(
                "EEE MMM dd HH:mm:ss Z yyyy");
        DateFormat outputDF = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        System.out.println(outputDF.format(inputDF.parse("Thu Feb 02 12:00:00 GMT-12:00 2012")));
于 2012-05-29T10:04:48.247 に答える
0
String dateStart = "Thu Feb 02 12:00:00 GMT-12:00 2012";
SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
Date d1 = format.parse(**dateStart**);
System.out.prinln("formatted date.." + d1);
于 2014-03-05T10:50:34.237 に答える
0
String strDate = "Thu Feb 02 12:00:00 GMT-12:00 2012";
DateFormat dateFormat = new SimpleDateFormat("MM/dd/yyyy - HH:mm:ss");
dateFormat.format(strDate);

And to get the result in Date, You can use the following :

Date d = new Date(dateFormat.format(strDate));
于 2012-05-30T04:45:23.253 に答える