com.liferay.portal.kernel.util.TimeZoneUtil Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of com.liferay.portal.kernel Show documentation
Show all versions of com.liferay.portal.kernel Show documentation
Contains interfaces for the portal services. Interfaces are only loaded by the global class loader and are shared by all plugins.
/**
* Copyright (c) 2000-present Liferay, Inc. All rights reserved.
*
* This library is free software; you can redistribute it and/or modify it under
* the terms of the GNU Lesser General Public License as published by the Free
* Software Foundation; either version 2.1 of the License, or (at your option)
* any later version.
*
* This library is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
* FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
* details.
*/
package com.liferay.portal.kernel.util;
import com.liferay.portal.kernel.security.pacl.permission.PortalRuntimePermission;
import java.util.Map;
import java.util.TimeZone;
import java.util.concurrent.ConcurrentHashMap;
/**
* @author Brian Wing Shun Chan
* @author Raymond Augé
*/
public class TimeZoneUtil {
public static final TimeZone GMT = TimeZone.getTimeZone("GMT");
public static TimeZone getDefault() {
TimeZone timeZone = TimeZoneThreadLocal.getDefaultTimeZone();
if (timeZone != null) {
return timeZone;
}
return _timeZone;
}
public static TimeZoneUtil getInstance() {
PortalRuntimePermission.checkGetBeanProperty(TimeZoneUtil.class);
return new TimeZoneUtil();
}
public static TimeZone getTimeZone(String timeZoneId) {
TimeZone timeZone = _timeZones.get(timeZoneId);
if (timeZone == null) {
timeZone = TimeZone.getTimeZone(timeZoneId);
_timeZones.put(timeZoneId, timeZone);
}
return timeZone;
}
public static void setDefault(String timeZoneId) {
PortalRuntimePermission.checkSetBeanProperty(TimeZoneUtil.class);
if (Validator.isNotNull(timeZoneId)) {
_timeZone = TimeZone.getTimeZone(timeZoneId);
}
}
private TimeZoneUtil() {
}
private static volatile TimeZone _timeZone = TimeZone.getTimeZone(
StringPool.UTC);
private static final Map _timeZones =
new ConcurrentHashMap<>();
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy