项目中用到的转换TIMEZONE的东西,备份。
By:Roy.LiuLast updated:2011-06-28
public String getGMTtime(String username,String curDate,int addday) throws Exception{
logger.info("TimeZoneConvert get username:"+username);
logger.info("TimeZoneConvert get curDate:"+curDate);
logger.info("TimeZoneConvert get addday:"+addday);
String curtimezone="";
curtimezone=getTimeZonebyUsername(username);
System.out.println("get timezone:"+curtimezone);
if ("".equals(curtimezone)){curtimezone="US/Eastern";}
String returnDate=curDate;
String returnDatestr="";
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
try {
/*STEP 1 convert to GMT time*/
String sourceGMD=DateUtil.string2TimezoneDefault(curDate,"GMT");
/*STEP 2 ADD DEAD LINE */
Date date=sdf.parse(sourceGMD);
date=DateUtil.calculateByDate(date, addday);
String convertDate=DateUtil.date2String("yyyy-MM-dd HH:mm:ss",date);
/*STEP 3 CONVERT GMT TO USER'S TIME*/
returnDatestr=DateUtil.string2TimezoneDefault(convertDate,curtimezone);
System.out.println("returnDatestr:"+returnDatestr);
/*STEP 4 CONVERT USER'S TIME TO GMT */
String newGMT=DateUtil.string2TimezoneDefault(returnDatestr,"GMT");
logger.info("the user timezone is: USA:"+returnDate);
return newGMT;
} catch (ParseException e) {
logger.info("getGMTtime error:"+e);
return returnDate;
}
}
logger.info("TimeZoneConvert get username:"+username);
logger.info("TimeZoneConvert get curDate:"+curDate);
logger.info("TimeZoneConvert get addday:"+addday);
String curtimezone="";
curtimezone=getTimeZonebyUsername(username);
System.out.println("get timezone:"+curtimezone);
if ("".equals(curtimezone)){curtimezone="US/Eastern";}
String returnDate=curDate;
String returnDatestr="";
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
try {
/*STEP 1 convert to GMT time*/
String sourceGMD=DateUtil.string2TimezoneDefault(curDate,"GMT");
/*STEP 2 ADD DEAD LINE */
Date date=sdf.parse(sourceGMD);
date=DateUtil.calculateByDate(date, addday);
String convertDate=DateUtil.date2String("yyyy-MM-dd HH:mm:ss",date);
/*STEP 3 CONVERT GMT TO USER'S TIME*/
returnDatestr=DateUtil.string2TimezoneDefault(convertDate,curtimezone);
System.out.println("returnDatestr:"+returnDatestr);
/*STEP 4 CONVERT USER'S TIME TO GMT */
String newGMT=DateUtil.string2TimezoneDefault(returnDatestr,"GMT");
logger.info("the user timezone is: USA:"+returnDate);
return newGMT;
} catch (ParseException e) {
logger.info("getGMTtime error:"+e);
return returnDate;
}
}
From:一号门
Previous:LDAP中属性值是多个的添加方法
COMMENTS