4cd10b01d4d936d86bac5db3e5de20067b503ca3.svn-base
1.5 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
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;
}
}
}