All Downloads are FREE. Search and download functionalities are using the official Maven repository.

cn.hutool.core.date.ZoneUtil Maven / Gradle / Ivy

There is a newer version: 5.8.33
Show newest version
package cn.hutool.core.date;

import java.time.ZoneId;
import java.util.TimeZone;

/**
 * {@link ZoneId}和{@link TimeZone}相关封装
 *
 * @author looly
 * @since 5.7.15
 */
public class ZoneUtil {

	/**
	 * {@link ZoneId}转换为{@link TimeZone},{@code null}则返回系统默认值
	 *
	 * @param zoneId {@link ZoneId},{@code null}则返回系统默认值
	 * @return {@link TimeZone}
	 */
	public static TimeZone toTimeZone(ZoneId zoneId) {
		if (null == zoneId) {
			return TimeZone.getDefault();
		}

		return TimeZone.getTimeZone(zoneId);
	}

	/**
	 * {@link TimeZone}转换为{@link ZoneId},{@code null}则返回系统默认值
	 *
	 * @param timeZone {@link TimeZone},{@code null}则返回系统默认值
	 * @return {@link ZoneId}
	 */
	public static ZoneId toZoneId(TimeZone timeZone) {
		if (null == timeZone) {
			return ZoneId.systemDefault();
		}

		return timeZone.toZoneId();
	}
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy