项目中用到的转换TIMEZONE的东西,备份。

    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;
        }
        
    }

除非申明,文章均为一号门原创,转载请注明本文地址,谢谢!
文章来自: 本站原创
引用通告: 查看所有引用 | 我要引用此文章
Tags:
相关日志:
评论: 1 | 引用: 0 | 查看次数: -
回复回复轻舞肥羊[2011-07-09 10:48 PM | del]
发表评论
昵 称:
密 码: 游客发言不需要密码.
内 容:
验证码: 验证码
选 项:
虽然发表评论不用注册,但是为了保护您的发言权,建议您注册帐号.