Use private UTC constant to avoid corruption of mutable constant

git-svn-id: https://svn.apache.org/repos/asf/commons/proper/lang/trunk@1077943 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Stephen Colebourne 2011-03-04 13:42:49 +00:00
parent f68bbdbbb5
commit cde62a69e1
1 changed files with 9 additions and 4 deletions

View File

@ -37,6 +37,11 @@ import java.util.TimeZone;
*/
public class DateFormatUtils {
/**
* The UTC time zone (often referred to as GMT).
* This is private as it is mutable.
*/
private static final TimeZone UTC_TIME_ZONE = TimeZone.getTimeZone("GMT");
/**
* ISO8601 formatter for date-time without time zone.
* The format used is <tt>yyyy-MM-dd'T'HH:mm:ss</tt>.
@ -125,7 +130,7 @@ public class DateFormatUtils {
* @return the formatted date
*/
public static String formatUTC(long millis, String pattern) {
return format(new Date(millis), pattern, DateUtils.UTC_TIME_ZONE, null);
return format(new Date(millis), pattern, UTC_TIME_ZONE, null);
}
/**
@ -136,7 +141,7 @@ public class DateFormatUtils {
* @return the formatted date
*/
public static String formatUTC(Date date, String pattern) {
return format(date, pattern, DateUtils.UTC_TIME_ZONE, null);
return format(date, pattern, UTC_TIME_ZONE, null);
}
/**
@ -148,7 +153,7 @@ public class DateFormatUtils {
* @return the formatted date
*/
public static String formatUTC(long millis, String pattern, Locale locale) {
return format(new Date(millis), pattern, DateUtils.UTC_TIME_ZONE, locale);
return format(new Date(millis), pattern, UTC_TIME_ZONE, locale);
}
/**
@ -160,7 +165,7 @@ public class DateFormatUtils {
* @return the formatted date
*/
public static String formatUTC(Date date, String pattern, Locale locale) {
return format(date, pattern, DateUtils.UTC_TIME_ZONE, locale);
return format(date, pattern, UTC_TIME_ZONE, locale);
}
/**