4cd10b01d4d936d86bac5db3e5de20067b503ca3.svn-base 1.5 KB
package com.espeed.tool;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.GregorianCalendar;
import java.util.TimeZone;
import java.util.Vector;

public final class TimeZoneTool {
   /**
    * 
    * @param nowDateTime  //需要转换的时间
    * @param defaulttime  //本地时区
    * @param timeZone 	   //需要转换的时间时区
    * @return   
    * @throws Exception
    */
    public static String timeZong(String nowDateTime,String defaulttime, String timeZone) throws Exception{
    		String localfromdate,localdate,result,localfromdates;
    		Date fromdate;
    		SimpleDateFormat sdf,dd,ss;
    		
	    	sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
	    	sdf.setTimeZone(TimeZone.getTimeZone(timeZone)); //设置时区
	    	fromdate = sdf.parse(nowDateTime);  //格式化时间
	    	
	    	dd = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
	    	ss = new SimpleDateFormat("yyyy年MM月dd日 HH时mm分");
	    	dd.setTimeZone(TimeZone.getTimeZone(defaulttime));  //设置本地时区
	    	
	    	localfromdate = dd.format(fromdate);  // 时区格式化后本地时间
	    	localdate =  dd.format(new Date());   // 格式化本地时间
	    	
	    	localfromdates = ss.format(fromdate);  //返回值
	    	
	    	long dingshi = DateFormat.minutes(localdate , localfromdate);
	    	if(dingshi>=59){
	    		return localfromdates;
	    	}else{
	    		result="定时时间必须大于北京时间1个小时";
	    		return result;
	    	}
    }
	  
}