对于这个烦人的问题,我已经束手无策了。基本上很久都解决不了这个问题。
java.util.Calendar calendar_now = java.util.Calendar.getInstance();
java.util.Calendar calendar_entry = java.util.Calendar.getInstance();
java.util.Date dt = new Date();
java.text.SimpleDateFormat formatter;
try{
// if(this.Time.length() == 0) {this.Time = "00:00";}
//this.Time = "00:00";
// System.out.println("*" + this.Time + "*");
if((this.Time.substring(this.Time.length() - 2) == "am")||(this.Time.substring(this.Time.length() - 2) == "pm"))
{
formatter = new SimpleDateFormat("yyyy E MMM d H:mmaa z",Locale.US);
dt = (Date)formatter.parse(calendar_now.get(java.util.Calendar.YEAR) + " " + this.Date + " " + this.Time + " EST");
//calendar_entry.setTimeZone(java.util.TimeZone.getTimeZone("America/New_York"));
}
calendar_entry.setTime(dt);
if (calendar_entry.get(java.util.Calendar.MONTH) < calendar_now.get(java.util.Calendar.MONTH)){
calendar_entry.set(java.util.Calendar.YEAR,calendar_now.get(java.util.Calendar.YEAR) + 1);
}
else{
calendar_entry.set(java.util.Calendar.YEAR,calendar_now.get(java.util.Calendar.YEAR));
}
// calendar_entry.setTimeZone(java.util.TimeZone.getTimeZone("GMT"));
System.out.println(calendar_now.get(java.util.Calendar.YEAR) + " " + this.Date + " " + this.Time + " EST");
System.out.println(dt.toString());
System.out.println(calendar_entry);
这会产生:
2010 年 10 月 1 日星期五美国东部标准时间上午 10:00 1970 年 10 月 1 日星期四 10:00:00 SGT java.util.GregorianCalendar[time=?,areFieldsSet=false,areAllFieldsSet=true,lenient=true,zone=sun.uti l.calendar.ZoneInfo[id="GMT",offset=0,dstSavings=0,useDaylight=false,transitions=0,lastRule=null],fi rstDayOfWeek=1,minimalDaysInFirstWeek=1,ERA=1,YEAR=2010,MONTH=9,WEEK_OF_YEAR=40,WEEK_OF_MONTH=1,DAY_ OF_MONTH=1,DAY_OF_YEAR=274,DAY_OF_WEEK=5,DAY_OF_WEEK_IN_MONTH=1,AM_PM=0,HOUR=2,HOUR_OF_DAY=2,MINUTE= 30,SECOND=0,MILLISECOND=0,ZONE_OFFSET=0,DST_OFFSET=0]
问题是……为什么?