테스트

aion-server 4.8

Gitteol
최고관리자 · 1 · 💬 0 클론/새로받기
 4.8 61f661d · 1 commits 새로받기(Pull)
game-server/src/com/aionemu/gameserver/utils/time/ServerTime.java
package com.aionemu.gameserver.utils.time;

import java.time.Instant;
import java.time.LocalDateTime;
import java.time.ZonedDateTime;
import java.util.Date;

import com.aionemu.gameserver.configs.main.GSConfig;

/**
 * This class is used to tell the actual server time (not game time!), independent of the systems or JVM's time zone settings. It should be
 * used wherever simple timestamp checks aren't sufficient, to ensure time zone consistency throughout all classes.
 * 
 * @author Neon
 */
public final class ServerTime {

	/**
	 * @return The current server time (not game time!)
	 */
	public static ZonedDateTime now() {
		return ZonedDateTime.now(GSConfig.TIME_ZONE_ID);
	}

	/**
	 * @param localDateTime
	 * @return The server time at the given date
	 */
	public static ZonedDateTime of(LocalDateTime localDateTime) {
		return ZonedDateTime.of(localDateTime, GSConfig.TIME_ZONE_ID);
	}

	/**
	 * @param date
	 * @return The server time at the given (UTC) date
	 */
	public static ZonedDateTime atDate(Date date) {
		return ZonedDateTime.ofInstant(date.toInstant(), GSConfig.TIME_ZONE_ID);
	}

	/**
	 * @param epochMilli
	 *          - the milliseconds since the epoch of 1970-01-01T00:00:00 UTC
	 * @return The server time at the given date
	 */
	public static ZonedDateTime ofEpochMilli(long epochMilli) {
		return ZonedDateTime.ofInstant(Instant.ofEpochMilli(epochMilli), GSConfig.TIME_ZONE_ID);
	}

	/**
	 * @param epochSecond
	 *          - the seconds since the epoch of 1970-01-01T00:00:00 UTC
	 * @return The server time at the given date
	 */
	public static ZonedDateTime ofEpochSecond(long epochSecond) {
		return ZonedDateTime.ofInstant(Instant.ofEpochSecond(epochSecond), GSConfig.TIME_ZONE_ID);
	}

	/**
	 * @param text
	 * @return The server time from the parsed {@link ZonedDateTime}
	 * @see ZonedDateTime#parse(CharSequence)
	 */
	public static ZonedDateTime parse(CharSequence text) {
		return ZonedDateTime.parse(text).withZoneSameInstant(GSConfig.TIME_ZONE_ID);
	}

	/**
	 * @param text
	 * @return The server time from the parsed {@link LocalDateTime}
	 * @see LocalDateTime#parse(CharSequence)
	 */
	public static ZonedDateTime parseLocal(CharSequence text) {
		return of(LocalDateTime.parse(text));
	}

	/**
	 * @return The daylight savings offset in seconds at the current date.
	 */
	public static int getDaylightSavings() {
		return (int) GSConfig.TIME_ZONE_ID.getRules().getDaylightSavings(Instant.now()).getSeconds();
	}

	/**
	 * @return The offset to UTC in seconds at the current date (including daylight savings).
	 */
	public static int getOffset() {
		return GSConfig.TIME_ZONE_ID.getRules().getOffset(Instant.now()).getTotalSeconds();
	}

	/**
	 * @return The standard offset to UTC in seconds (excluding daylight savings).
	 */
	public static int getStandardOffset() {
		return GSConfig.TIME_ZONE_ID.getRules().getStandardOffset(Instant.now()).getTotalSeconds();
	}
}

📎 첨부파일

댓글 작성 권한이 없습니다.
🏆 포인트 랭킹 TOP 10
순위 닉네임 포인트
1 no_profile 타키야겐지쪽지보내기 자기소개 아이디로 검색 전체게시물 102,949
2 no_profile 동가리쪽지보내기 자기소개 아이디로 검색 전체게시물 63,733
3 no_profile 라프텔쪽지보내기 자기소개 아이디로 검색 전체게시물 51,771
4 no_profile 불멸의행복쪽지보내기 자기소개 아이디로 검색 전체게시물 36,923
5 서번트쪽지보내기 자기소개 아이디로 검색 전체게시물 35,011
6 no_profile 닥터스쪽지보내기 자기소개 아이디로 검색 전체게시물 29,470
7 no_profile 검은고양이쪽지보내기 자기소개 아이디로 검색 전체게시물 29,077
8 no_profile Revolution쪽지보내기 자기소개 아이디로 검색 전체게시물 28,199
9 no_profile 보거스쪽지보내기 자기소개 아이디로 검색 전체게시물 26,731
10 no_profile 호롤롤로쪽지보내기 자기소개 아이디로 검색 전체게시물 17,020
알림 0