Skip to content

Commit

Permalink
1.增加获取指定时区的方法
Browse files Browse the repository at this point in the history
  • Loading branch information
Leo.ZhangTJ authored and Leo.ZhangTJ committed Jan 2, 2019
1 parent aeaa5ee commit 154700c
Showing 1 changed file with 14 additions and 1 deletion.
15 changes: 14 additions & 1 deletion utils/src/main/java/com/leo/utils/TimeUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import java.util.Calendar;
import java.util.Date;
import java.util.Locale;
import java.util.TimeZone;

/**
* @author leo
Expand Down Expand Up @@ -49,7 +50,7 @@ private TimeUtils() {
/**
* 默认时间格式
*/
private static final DateFormat DEFAULT_FORMAT = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss", Locale.getDefault());
private static final DateFormat DEFAULT_FORMAT = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");

/**
* 英文简写(默认)如:2010-12-01
Expand Down Expand Up @@ -81,6 +82,8 @@ private TimeUtils() {
*/
public static final String FORMAT_FULL_CN = "yyyy年MM月dd日 HH时mm分ss秒SSS毫秒";

public static final String BEIJING_TIMEZONE = "GMT+8";

public static DateFormat getDateFormate(final String format) {
return new SimpleDateFormat(format, Locale.getDefault());
}
Expand Down Expand Up @@ -160,4 +163,14 @@ public static boolean isSameMinute(String t1, String t2) {
return t1.substring(14, 16).equals(t2.substring(14, 16));
}

public static String getTimeWithTimeZone(String format, String timeZone) {
Date date = new Date(System.currentTimeMillis());
SimpleDateFormat dateFormat = new SimpleDateFormat(format);
dateFormat.setTimeZone(TimeZone.getTimeZone(timeZone));
return dateFormat.format(date);
}

public static String getTimeWithTimeZone() {
return getTimeWithTimeZone(FORMAT_LONG, BEIJING_TIMEZONE);
}
}

0 comments on commit 154700c

Please sign in to comment.