다음을 통해 공유


TimeZone.GetUtcOffset 메서드

지정된 현지 시간에 대한 UTC(지역 표준시) 오프셋을 반환합니다.

네임스페이스: System
어셈블리: mscorlib(mscorlib.dll)

구문

‘선언
Public MustOverride Function GetUtcOffset ( _
    time As DateTime _
) As TimeSpan
‘사용 방법
Dim instance As TimeZone
Dim time As DateTime
Dim returnValue As TimeSpan

returnValue = instance.GetUtcOffset(time)
public abstract TimeSpan GetUtcOffset (
    DateTime time
)
public:
virtual TimeSpan GetUtcOffset (
    DateTime time
) abstract
public abstract TimeSpan GetUtcOffset (
    DateTime time
)
public abstract function GetUtcOffset (
    time : DateTime
) : TimeSpan

매개 변수

  • time
    현지 날짜와 시간입니다.

반환 값

틱 단위로 측정되는 time에서의 UTC 오프셋입니다.

설명

UTC(지역 표준시)를 이전에는 GMT(그리니치 표준시)라고 했습니다. 현지 시간은 사용하고 있는 컴퓨터의 날짜와 시간입니다. 오프셋은 현지 시간과 UTC 간의 차이입니다. 즉, 다음과 같은 공식이 적용됩니다.

현지 시간 = UTC + 오프셋

time은 그레고리오력 및 이 인스턴스가 나타내는 표준 시간대에 속해야 합니다. time이 일광 절약 시간에 해당되는 경우, 이 메서드는 일광 절약 시간대에 대한 UTC 오프셋을 반환합니다. 이 메서드는 시스템의 일광 절약 시간 규칙을 사용합니다.

예를 들어, 오프셋이 -8시간인 미태평양 표준시에서 GetUtcOffset(new DateTime(1999, 1, 1))은 -288000000000을 반환합니다.

예제

다음 코드 예제에서는 GetUtcOffset 메서드를 사용하여 일부 현지 시간에 대한 UTC 오프셋을 반환합니다.

' Example of the TimeZone.ToLocalTime( DateTime ) and 
' TimeZone.GetUtcOffset( DateTime ) methods.
Imports System
Imports Microsoft.VisualBasic

Module UTCTimeDemo

    Sub Main( )

        Const headFmt As String = "{0,-20}{1,-20}{2,-12}{3}"

        ' Get the local time zone and a base Coordinated Universal 
        ' Time (UTC).
        Dim localZone As TimeZone = TimeZone.CurrentTimeZone
        Dim baseUTC As DateTime = new DateTime( 2000, 1, 1 )

        Console.WriteLine( "This example of " & vbCrLf & _
            "   TimeZone.ToLocalTime( DateTime ) and" & vbCrLf & _
            "   TimeZone.GetUtcOffset( DateTime ) " & vbCrLf & _
            "generates the following output, which varies " & _
            "depending on the time zone " & vbCrLf & "in which " & _
            "it is run. The example creates several Coordinated " & _
            "Universal " & vbCrLf & "Times (UTC), displays the " & _
            "corresponding local times and UTC offsets, " & _
            vbCrLf & "and shows if the times occur in daylight " & _
            "saving time (DST)." & vbCrLf )
        Console.WriteLine( "Local time: {0}" & vbCrLf, _
            localZone.StandardName )

        Console.WriteLine( headFmt, "UTC", "Local Time", _
            " Offset", "DST?" )
        Console.WriteLine( headFmt, "---", "----------", _
            " ------", "----" )

        ' Generate several UTC times.
        Dim loopX As Integer
        For loopX = 0 to 10

            ' Calculate the local time and UTC offset.
            Dim localTime As DateTime = _
                localZone.ToLocalTime( baseUTC )
            Dim localOffset As TimeSpan = _
                localZone.GetUtcOffset( localTime )

            Console.WriteLine( "{0,-20:yyyy-MM-dd HH:mm}" & _
                "{1,-20:yyyy-MM-dd HH:mm}{2,-12}{3}", _
                baseUTC, localTime, localOffset, _
                localZone.IsDaylightSavingTime( localTime ) )
            
            ' Advance to another UTC.
            baseUTC = baseUTC.AddDays( 155.55 )
        Next loopX
    End Sub 
End Module 

' This example of
'    TimeZone.ToLocalTime( DateTime ) and
'    TimeZone.GetUtcOffset( DateTime )
' generates the following output, which varies depending on the time zone
' in which it is run. The example creates several Coordinated Universal
' Times (UTC), displays the corresponding local times and UTC offsets,
' and shows if the times occur in daylight saving time (DST).
' 
' Local time: Pacific Standard Time
' 
' UTC                 Local Time           Offset     DST?
' ---                 ----------           ------     ----
' 2000-01-01 00:00    1999-12-31 16:00    -08:00:00   False
' 2000-06-04 13:12    2000-06-04 06:12    -07:00:00   True
' 2000-11-07 02:24    2000-11-06 18:24    -08:00:00   False
' 2001-04-11 15:36    2001-04-11 08:36    -07:00:00   True
' 2001-09-14 04:48    2001-09-13 21:48    -07:00:00   True
' 2002-02-16 18:00    2002-02-16 10:00    -08:00:00   False
' 2002-07-22 07:12    2002-07-22 00:12    -07:00:00   True
' 2002-12-24 20:24    2002-12-24 12:24    -08:00:00   False
' 2003-05-29 09:36    2003-05-29 02:36    -07:00:00   True
' 2003-10-31 22:48    2003-10-31 14:48    -08:00:00   False
' 2004-04-04 12:00    2004-04-04 05:00    -07:00:00   True
// Example of the TimeZone.ToLocalTime( DateTime ) and 
// TimeZone.GetUtcOffset( DateTime ) methods.
using System;

class UTCTimeDemo
{
    static void Main( )
    {
        const string headFmt = "{0,-20}{1,-20}{2,-12}{3}";

        // Get the local time zone and a base Coordinated Universal 
        // Time (UTC).
        TimeZone localZone = TimeZone.CurrentTimeZone;
        DateTime baseUTC = new DateTime( 2000, 1, 1 );

        Console.WriteLine( "This example of \n" +
            "   TimeZone.ToLocalTime( DateTime ) and\n" +
            "   TimeZone.GetUtcOffset( DateTime ) \ngenerates the " +
            "following output, which varies depending on the time " +
            "zone \nin which it is run. The example creates several " +
            "Coordinated Universal \nTimes (UTC), displays the " +
            "corresponding local times and UTC offsets, \nand shows " +
            "if the times occur in daylight saving time (DST)." );
        Console.WriteLine( "\nLocal time: {0}\n", 
            localZone.StandardName );

        Console.WriteLine( headFmt, "UTC", "Local Time", 
            " Offset", "DST?" );
        Console.WriteLine( headFmt, "---", "----------", 
            " ------", "----" );

        // Generate several UTC times.
        for( int loopX = 0; loopX <= 10; loopX++ )
        {
            // Calculate the local time and UTC offset.
            DateTime localTime = localZone.ToLocalTime( baseUTC );
            TimeSpan localOffset = 
                localZone.GetUtcOffset( localTime );

            Console.WriteLine( "{0,-20:yyyy-MM-dd HH:mm}" +
                "{1,-20:yyyy-MM-dd HH:mm}{2,-12}{3}", 
                baseUTC, localTime, localOffset, 
                localZone.IsDaylightSavingTime( localTime ) );
            
            // Advance to another UTC.
            baseUTC = baseUTC.AddDays( 155.55 );
        }
    } 
} 

/*
This example of
   TimeZone.ToLocalTime( DateTime ) and
   TimeZone.GetUtcOffset( DateTime )
generates the following output, which varies depending on the time zone
in which it is run. The example creates several Coordinated Universal
Times (UTC), displays the corresponding local times and UTC offsets,
and shows if the times occur in daylight saving time (DST).

Local time: Pacific Standard Time

UTC                 Local Time           Offset     DST?
---                 ----------           ------     ----
2000-01-01 00:00    1999-12-31 16:00    -08:00:00   False
2000-06-04 13:12    2000-06-04 06:12    -07:00:00   True
2000-11-07 02:24    2000-11-06 18:24    -08:00:00   False
2001-04-11 15:36    2001-04-11 08:36    -07:00:00   True
2001-09-14 04:48    2001-09-13 21:48    -07:00:00   True
2002-02-16 18:00    2002-02-16 10:00    -08:00:00   False
2002-07-22 07:12    2002-07-22 00:12    -07:00:00   True
2002-12-24 20:24    2002-12-24 12:24    -08:00:00   False
2003-05-29 09:36    2003-05-29 02:36    -07:00:00   True
2003-10-31 22:48    2003-10-31 14:48    -08:00:00   False
2004-04-04 12:00    2004-04-04 05:00    -07:00:00   True
*/ 
// Example of the TimeZone::ToLocalTime( DateTime ) and 
// TimeZone::GetUtcOffset( DateTime ) methods.
using namespace System;
int main()
{
   String^ headFmt = "{0,-20}{1,-20}{2,-12}{3}";
   
   // Get the local time zone and a base Coordinated Universal 
   // Time (UTC).
   TimeZone^ localZone = TimeZone::CurrentTimeZone;
   DateTime baseUTC = DateTime(2000,1,1);
   Console::WriteLine( "This example of \n"
   "   TimeZone::ToLocalTime( DateTime ) and\n"
   "   TimeZone::GetUtcOffset( DateTime ) \ngenerates the "
   "following output, which varies depending on the time "
   "zone \nin which it is run. The example creates several "
   "Coordinated Universal \nTimes (UTC), displays the "
   "corresponding local times and UTC offsets, \nand shows "
   "if the times occur in daylight saving time (DST)." );
   Console::WriteLine( "\nLocal time: {0}\n", localZone->StandardName );
   Console::WriteLine( headFmt, "UTC", "Local Time", " Offset", "DST?" );
   Console::WriteLine( headFmt, "---", "----------", " ------", "----" );
   
   // Generate several UTC times.
   for ( int loopX = 0; loopX <= 10; loopX++ )
   {
      
      // Calculate the local time and UTC offset.
      DateTime localTime = localZone->ToLocalTime( baseUTC );
      TimeSpan localOffset = localZone->GetUtcOffset( localTime );
      Console::WriteLine( "{0,-20:yyyy-MM-dd HH:mm}"
      "{1,-20:yyyy-MM-dd HH:mm}{2,-12}{3}", baseUTC, localTime, localOffset, localZone->IsDaylightSavingTime( localTime ) );
      
      // Advance to another UTC.
      baseUTC = baseUTC.AddDays( 155.55 );

   }
}

/*
This example of
   TimeZone::ToLocalTime( DateTime ) and
   TimeZone::GetUtcOffset( DateTime )
generates the following output, which varies depending on the time zone
in which it is run. The example creates several Coordinated Universal
Times (UTC), displays the corresponding local times and UTC offsets,
and shows if the times occur in daylight saving time (DST).

Local time: Pacific Standard Time

UTC                 Local Time           Offset     DST?
---                 ----------           ------     ----
2000-01-01 00:00    1999-12-31 16:00    -08:00:00   False
2000-06-04 13:12    2000-06-04 06:12    -07:00:00   True
2000-11-07 02:24    2000-11-06 18:24    -08:00:00   False
2001-04-11 15:36    2001-04-11 08:36    -07:00:00   True
2001-09-14 04:48    2001-09-13 21:48    -07:00:00   True
2002-02-16 18:00    2002-02-16 10:00    -08:00:00   False
2002-07-22 07:12    2002-07-22 00:12    -07:00:00   True
2002-12-24 20:24    2002-12-24 12:24    -08:00:00   False
2003-05-29 09:36    2003-05-29 02:36    -07:00:00   True
2003-10-31 22:48    2003-10-31 14:48    -08:00:00   False
2004-04-04 12:00    2004-04-04 05:00    -07:00:00   True
*/
// Example of the TimeZone.ToLocalTime( DateTime ) and 
// TimeZone.GetUtcOffset( DateTime ) methods.
import System.*;

class UTCTimeDemo
{
    public static void main(String[] args)
    {
        final String headFmt = "{0,-20}{1,-20}{2,-12}{3}";

        // Get the local time zone and a base Coordinated Universal 
        // Time (UTC).
        TimeZone localZone = TimeZone.get_CurrentTimeZone();
        DateTime baseUTC = new DateTime(2000, 1, 1);
        Console.WriteLine(("This example of \n" 
            + "TimeZone.ToLocalTime( DateTime ) and\n" 
            + "   TimeZone.GetUtcOffset( DateTime ) \ngenerates the " 
            + "following output, which varies depending on the time " 
            + "zone \nin which it is run. The example creates several " 
            + "Coordinated Universal \nTimes (UTC), displays the " 
            + "corresponding local times and UTC offsets, \nand shows " 
            + "if the times occur in daylight saving time (DST)."));
        Console.WriteLine("\nLocal time: {0}\n",localZone.get_StandardName());
        Console.WriteLine(headFmt, new Object[] { "UTC", "Local Time",
            " Offset","DST?" });
        Console.WriteLine(headFmt, new Object[] { "---", "----------",
            " ------", "----" });

        // Generate several UTC times.
        for (int loopX = 0; loopX <= 10; loopX++) {
            // Calculate the local time and UTC offset.
            DateTime localTime = localZone.ToLocalTime(baseUTC);
            TimeSpan localOffset = localZone.GetUtcOffset(localTime);

            Console.WriteLine("{0,-20:yyyy-MM-dd HH:mm}" 
                +    "{1,-20:yyyy-MM-dd HH:mm}{2,-12}{3}",
                new Object[] {baseUTC, localTime, localOffset,
                (System.Boolean)localZone.IsDaylightSavingTime(localTime) });

            // Advance to another UTC.
            baseUTC = baseUTC.AddDays(155.55);
        }
    } //main
} //UTCTimeDemo

/*
This example of
   TimeZone.ToLocalTime( DateTime ) and
   TimeZone.GetUtcOffset( DateTime )
generates the following output, which varies depending on the time zone
in which it is run. The example creates several Coordinated Universal
Times (UTC), displays the corresponding local times and UTC offsets,
and shows if the times occur in daylight saving time (DST).

Local time: Pacific Standard Time

UTC                 Local Time           Offset     DST?
---                 ----------           ------     ----
2000-01-01 00:00    1999-12-31 16:00    -08:00:00   False
2000-06-04 13:12    2000-06-04 06:12    -07:00:00   True
2000-11-07 02:24    2000-11-06 18:24    -08:00:00   False
2001-04-11 15:36    2001-04-11 08:36    -07:00:00   True
2001-09-14 04:48    2001-09-13 21:48    -07:00:00   True
2002-02-16 18:00    2002-02-16 10:00    -08:00:00   False
2002-07-22 07:12    2002-07-22 00:12    -07:00:00   True
2002-12-24 20:24    2002-12-24 12:24    -08:00:00   False
2003-05-29 09:36    2003-05-29 02:36    -07:00:00   True
2003-10-31 22:48    2003-10-31 14:48    -08:00:00   False
2004-04-04 12:00    2004-04-04 05:00    -07:00:00   True
*/

플랫폼

Windows 98, Windows 2000 SP4, Windows CE, Windows Millennium Edition, Windows Mobile for Pocket PC, Windows Mobile for Smartphone, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition

.NET Framework에서 모든 플래폼의 모든 버전을 지원하지는 않습니다. 지원되는 버전의 목록은 시스템 요구 사항을 참조하십시오.

버전 정보

.NET Framework

2.0, 1.1, 1.0에서 지원

.NET Compact Framework

2.0, 1.0에서 지원

참고 항목

참조

TimeZone 클래스
TimeZone 멤버
System 네임스페이스