
com.magictools.core.date.ZoneUtil Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of magic-tools-all Show documentation
Show all versions of magic-tools-all Show documentation
magic-tools 是一个小而全的Java工具类库,通过静态方法封装,降低相关API的学习成本,提高工作效率,使Java拥有函数式语言般的优雅,让Java语言也可以“甜甜的”。
The newest version!
package com.magictools.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 - 2025 Weber Informatics LLC | Privacy Policy