我有一个格式的日期字符串MM/dd/yyyy
,我正在使用它来解析SimpleDateFormat
现在说startDateString
是11/26/2012
下面给出的代码。我将时区设置为America/New_York
SimpleDateFormat df=new SimpleDateFormat("MM/dd/yyyy");
Date st = df.parse(startDateString);
Calendar startDate = Calendar.getInstance(TimeZone.getTimeZone("America/New_York"));
System.out.println("BEFORE : Start Date :"+startDate.getTime());
startDate.setTime(st);
System.out.println("AFTER : Start Date :"+startDate.getTime());
DateTimeZone timezone = DateTimeZone.forID("America/New_York");
DateTime actualStartDate = new DateTime(startDate,timezone);
System.out.println("JODA DATE TIME "+ actualStartDate);
上面的代码片段的outout:
BEFORE : Start Date :Tue Nov 27 12:26:51 IST 2012
AFTER : Start Date :Mon Nov 26 00:00:00 IST 2012 //ok it sets date to 26th
//with all time parameters as 0.
JODA DATE TIME 2012-11-25T13:30:00.000-05:00 // here the date and
// time parameter are changed
当我actualStartDate
像这样创建我的问题时,我的问题是:
DateTime actualStartDate = new DateTime(startDate,timezone);
日期更改为 25,时间更改为 13:00:00
我认为这是因为印度和美国之间的时区差异(从 IST 印度时间开始总计 -10:30)
我想要的是JODA DATE TIME 2012-11-26T00:00:00.000-05:00
我是否手动将startDate
日历实例中的时间参数设置为0
?