PROGRAMING/JAVA

[JAVA] UTC/GMT Local Time 시간 변환

donghunl 2011. 6. 3. 06:03
반응형

// Local Time -> UTC/GMT Time
public static long convertLocalTimeToUTC(long pv_localDateTime)
{
    long lv_UTCTime = pv_localDateTime;
    
    TimeZone z = TimeZone.getDefault();
    //int offset = z.getRawOffset(); // The offset not includes daylight savings time
    int offset = z.getOffset(pv_localDateTime); // The offset includes daylight savings time

    lv_UTCTime = pv_localDateTime - offset;

    return lv_UTCTime;
}

// UTC/GMT Time -> Local Time
public static long convertUTCToLocalTime(long pv_UTCDateTime)
{
    long lv_localDateTime = pv_UTCDateTime;
    
    TimeZone z = TimeZone.getDefault();
    //int offset = z.getRawOffset(); // The offset not includes daylight savings time
    int offset = z.getOffset(pv_UTCDateTime); // The offset includes daylight savings time
    
    lv_localDateTime = pv_UTCDateTime + offset;
    
    return lv_localDateTime;
}
반응형

'PROGRAMING > JAVA' 카테고리의 다른 글

[JAVA] 날짜 변환  (0) 2011.04.26