如何在java中转换日期

如何在java中转换日期,java,datetime,date,timestamp,Java,Datetime,Date,Timestamp,我是android新手。 我必须将以下日期转换为此时间戳(Wed Oct 12 14:17:42 GMT+05:30 2011) 这是我通过标题从服务器获取的日期。我已将其转换为字符串对象。现在我必须将其转换为日期格式,如:Wed Oct 12 14:17:42 GMT+05:30 2011 Thu, 27 May 2010 12:37:27 GMT 请您帮助我如何使用时间戳将其转换为(Wed Oct 12 14:17:42 GMT+05:30 2011)此格式。请查看DateFormat或S

我是android新手。 我必须将以下日期转换为此时间戳(
Wed Oct 12 14:17:42 GMT+05:30 2011

这是我通过标题从服务器获取的日期。我已将其转换为字符串对象。现在我必须将其转换为日期格式,如:
Wed Oct 12 14:17:42 GMT+05:30 2011

Thu, 27 May 2010 12:37:27 GMT

请您帮助我如何使用时间戳将其转换为(
Wed Oct 12 14:17:42 GMT+05:30 2011
)此格式。

请查看
DateFormat
SimpleDateFormat
,它们提供
parse()
format()
方法
DateFormat
提供了一系列标准格式,而
SimpleDateFormat
允许您提供自己的格式表达式

输入日期的示例:

//note that you need the locale as well, since the weekdays and months are written in a specific language, English in that case
SimpleDateFormat parseFormat = new SimpleDateFormat( "E, dd MMM yyyy HH:mm:ss z", Locale.ENGLISH );
SimpleDateFormat writeFormat = new SimpleDateFormat( "E MMM dd HH:mm:ss z yyyy", Locale.ENGLISH );
writeFormat.setTimeZone( TimeZone.getTimeZone( "GMT" ) );

Date tDate = parseFormat.parse( "Wed, 12 Oct 2011 14:17:42 GMT" );

System.out.println(writeFormat.format(tDate )); //Wed Oct 12 14:17:42 GMT 2011
编辑:如果您想要一个更可用的API,请尝试