如何在日期之间更改日期格式类型? [英] How to change Date format type between dates?

查看:59
本文介绍了如何在日期之间更改日期格式类型?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何将此日期类型"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"是字符串类型,如何转换"yyyy-MM-dd HH:mm:ss"的日期类型?

how to change this date type "Thu Feb 02 12:00:00 GMT-12:00 2012" to another date type "yyyy-mm-dd HH:mm:ss"? If "Thu Feb 02 12:00:00 GMT-12:00 2012" is the String type, how to convert Date type of "yyyy-MM-dd HH:mm:ss"?

java代码:

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);

输出为String类型.我想获取Date类型的输出,所以我添加了以下代码.

The output is String type. I wanna get Date type output so I added following code.

   Date outputDate = outputDF.parse(strDate);

但是我再次得到"EEE MMM dd HH:mm:ss Z yyyy"格式的日期.我想使用这种"yyyy-MM-dd HH:mm:ss"格式获取日期,并且还想要日期类型.

But I get again Date with this "EEE MMM dd HH:mm:ss Z yyyy" format. I want to get Date with this "yyyy-MM-dd HH:mm:ss" format and also want Date Type.

我还想获取输出类型为Date类型的格式.

推荐答案

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")));

这篇关于如何在日期之间更改日期格式类型?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆