如何在Java中解析以下日期格式Mon Nov 09 2015 00:00:00 GMT + 0530(India Standard Time) [英] how to parse the following date format Mon Nov 09 2015 00:00:00 GMT+0530 (India Standard Time) in java
本文介绍了如何在Java中解析以下日期格式Mon Nov 09 2015 00:00:00 GMT + 0530(India Standard Time)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我以 Mon Nov 09 2015 00:00:00 GMT + 0530
(印度标准时间)的格式获取日期.我必须将其转换为 dd/MM/yyyy
格式的sql日期.请帮忙.
I am getting the date in the format Mon Nov 09 2015 00:00:00 GMT+0530
(India Standard Time). I have to convert it to sql date of format dd/MM/yyyy
. Please help.
我尝试了下面的代码,但没有帮助
I tried below code but did not help
Date date = new java.sql.Date(
(new SimpleDateFormat("EEE MMM dd yyyy HH:mm:ss zz (zzzz)").parse("Mon Nov 09 2015 00:00:00 GMT+0530 (India Standard Time)"))
.getTime());
推荐答案
Something like below, also refer here for Java SimpleDateFormat
public static void main(String[] args) throws ParseException {
String time = "Mon Nov 09 2015 00:00:00 GMT+0530 (India Standard Time)";
DateFormat inputFormat = new SimpleDateFormat(
"E MMM dd yyyy HH:mm:ss 'GMT'z", Locale.ENGLISH);
Date date = inputFormat.parse(time);
System.out.println(date);
SimpleDateFormat formatter = new SimpleDateFormat("dd/MM/yyyy", Locale.US);
System.out.println(formatter.format(date));
}
输出
Mon Nov 09 00:00:00 IST 2015
09/11/2015
这篇关于如何在Java中解析以下日期格式Mon Nov 09 2015 00:00:00 GMT + 0530(India Standard Time)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文