TimeZone.ToUniversalTime メソッドとは? わかりやすく解説

Weblio 辞書 > コンピュータ > .NET Framework クラス ライブラリ リファレンス > TimeZone.ToUniversalTime メソッドの意味・解説 

TimeZone.ToUniversalTime メソッド

指定した現地時間対応する世界協定時刻 (UTC: Coordinated Universal Time) を返します

名前空間: System
アセンブリ: mscorlib (mscorlib.dll 内)
構文構文

解説解説
使用例使用例

ToUniversalTime メソッド使用して選択した現地時間対応する UTC 時間返すコード例次に示します

' Example of the TimeZone.IsDaylightSavingTime( DateTime ),
' TimeZone.IsDaylightSavingTime( DateTime, DaylightTime ), and 
' TimeZone.ToUniversalTime( DateTime ) methods.
Imports System
Imports System.Globalization
Imports Microsoft.VisualBasic

Module DaylightTimeDemo

    Sub Main( )

        Const headFmt As String
 = "{0,-22}{1,-10}{2,-10}{3,-10}{4}"

        ' Get the local time zone and a base local time.
        Dim localZone As TimeZone = TimeZone.CurrentTimeZone
        Dim localTime As DateTime = new
 DateTime( 2001, 1, 1 )

        Console.WriteLine( "This example of " &
 vbCrLf & _
            "   TimeZone.IsDaylightSavingTime( DateTime ), "
 & _
            vbCrLf & "   TimeZone.IsDaylightSavingTime( "
 & _
            "DateTime, DaylightTime ), and " &
 vbCrLf & _
            "   TimeZone.ToUniversalTime( DateTime )"
 & vbCrLf & _
            "generates the following output, which varies "
 & _
            "depending on the " & vbCrLf &
 "time zone in which " & _
            "it is run." & vbCrLf )
        Console.WriteLine( "The example creates "
 & _
            "several local times and the corresponding "
 & vbCrLf & _
            "Coordinated Universal Times (UTC) and shows if "
 & _
            "they occur in " & vbCrLf & "daylight
 saving time " & _
            "(DST), both for specified years and for "
 & vbCrLf & _
            "any year." & vbCrLf )
        Console.WriteLine( "Local time: {0}" &
 vbCrLf, _
            localZone.StandardName )

        Console.WriteLine( headFmt, "Local Date and Time",
 _
            "2001 DST?", "2002
 DST?", "Any DST?", "Corresponding
 UTC" )
        Console.WriteLine( headFmt, "-------------------",
 _
            "---------", "---------",
 "--------", "-----------------"
 )

        ' Create DaylightTime objects for specific years.
        Dim daylight2001 As DaylightTime =
 _
            localZone.GetDaylightChanges( 2001 )
        Dim daylight2002 As DaylightTime =
 _
            localZone.GetDaylightChanges( 2002 )

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

            ' Calculate the corresponding UTC.
            Dim utcTime As DateTime = _
                localZone.ToUniversalTime( localTime )

            ' Show if dates and times occur in daylight saving 
            ' time, for specified years and for any year.
            Console.WriteLine( "{0,-22:yyyy-MM-dd HH:mm}"
 & _
                "{1,-10}{2,-10}{3,-10}{4:yyyy-MM-dd HH:mm}",
 _
                localTime, _
                TimeZone.IsDaylightSavingTime( _
                    localTime, daylight2001 ), _
                TimeZone.IsDaylightSavingTime( _
                    localTime, daylight2002 ), _
                localZone.IsDaylightSavingTime( localTime ), _
                utcTime )
            
            ' Advance to another local time.
            localTime = localTime.AddDays( 109.1 )
        Next loopX
    End Sub
End Module 

' This example of
'    TimeZone.IsDaylightSavingTime( DateTime ),
'    TimeZone.IsDaylightSavingTime( DateTime, DaylightTime ), and
'    TimeZone.ToUniversalTime( DateTime )
' generates the following output, which varies depending on the
' time zone in which it is run.
' 
' The example creates several local times and the corresponding
' Coordinated Universal Times (UTC) and shows if they occur in
' daylight saving time (DST), both for specified years and for
' any year.
' 
' Local time: Pacific Standard Time
' 
' Local Date and Time   2001 DST? 2002 DST? Any DST?  Corresponding
 UTC
' -------------------   --------- --------- --------  -----------------
' 2001-01-01 00:00      False     False     False     2001-01-01 08:00
' 2001-04-20 02:24      True      False     True      2001-04-20 09:24
' 2001-08-07 04:48      True      False     True      2001-08-07 11:48
' 2001-11-24 07:12      False     False     False     2001-11-24 15:12
' 2002-03-13 09:36      False     False     False     2002-03-13 17:36
' 2002-06-30 12:00      False     True      True      2002-06-30 19:00
' 2002-10-17 14:24      False     True      True      2002-10-17 21:24
' 2003-02-03 16:48      False     False     False     2003-02-04 00:48
' 2003-05-23 19:12      False     False     True      2003-05-24 02:12
' 2003-09-09 21:36      False     False     True      2003-09-10 04:36
' 2003-12-28 00:00      False     False     False     2003-12-28 08:00
// Example of the TimeZone.IsDaylightSavingTime( DateTime ),
// TimeZone.IsDaylightSavingTime( DateTime, DaylightTime ), and 
// TimeZone.ToUniversalTime( DateTime ) methods.
using System;
using System.Globalization;

class DaylightTimeDemo
{
    static void Main( )
    {
        const string headFmt = "{0,-22}{1
,-10}{2,-10}{3,-10}{4}";

        // Get the local time zone and a base local time.
        TimeZone localZone = TimeZone.CurrentTimeZone;
        DateTime localTime = new DateTime( 2001, 1, 1 );

        Console.WriteLine( "This example of \n" +
            "   TimeZone.IsDaylightSavingTime( DateTime ), \n" +
            "   TimeZone.IsDaylightSavingTime( " +
            "DateTime, DaylightTime ), and \n" +
            "   TimeZone.ToUniversalTime( DateTime )\n" +
            "generates the following output, which varies " +
            "depending on the \ntime zone in which it is
 run.\n" );
        Console.WriteLine( "The example creates several local " +
            "times and the corresponding \nCoordinated Universal " +
            "Times (UTC) and shows if they occur in
 \ndaylight " +
            "saving time (DST), both for specified years
 " +
            "and for \nany year.\n" );
        Console.WriteLine( "Local time: {0}\n", 
            localZone.StandardName );

        Console.WriteLine( headFmt, "Local Date and Time", "2001 DST?",
 
            "2002 DST?", "Any DST?", "Corresponding UTC"
 );
        Console.WriteLine( headFmt, "-------------------", "---------",
 
            "---------", "--------", "-----------------"
 );

        // Create DaylightTime objects for specific years.
        DaylightTime daylight2001 = 
            localZone.GetDaylightChanges( 2001 );
        DaylightTime daylight2002 = 
            localZone.GetDaylightChanges( 2002 );

        // Generate several local times.
        for( int loopX = 0; loopX <= 10;
 loopX++ )
        {
            // Calculate the corresponding UTC.
            DateTime utcTime = 
                localZone.ToUniversalTime( localTime );

            // Show if dates and times occur in daylight saving 
            // time, for specified years and for any year.
            Console.WriteLine( "{0,-22:yyyy-MM-dd HH:mm}" +
                "{1,-10}{2,-10}{3,-10}{4:yyyy-MM-dd HH:mm}", 
                localTime, 
                TimeZone.IsDaylightSavingTime( 
                    localTime, daylight2001 ), 
                TimeZone.IsDaylightSavingTime( 
                    localTime, daylight2002 ), 
                localZone.IsDaylightSavingTime( localTime ), 
                utcTime );
            
            // Advance to another local time.
            localTime = localTime.AddDays( 109.1 );
        }
    } 
} 

/*
This example of
   TimeZone.IsDaylightSavingTime( DateTime ),
   TimeZone.IsDaylightSavingTime( DateTime, DaylightTime ), and
   TimeZone.ToUniversalTime( DateTime )
generates the following output, which varies depending on the
time zone in which it is run.

The example creates several local times and the corresponding
Coordinated Universal Times (UTC) and shows if they occur in
daylight saving time (DST), both for specified years and for
any year.

Local time: Pacific Standard Time

Local Date and Time   2001 DST? 2002 DST? Any DST?  Corresponding UTC
-------------------   --------- --------- --------  -----------------
2001-01-01 00:00      False     False     False     2001-01-01 08:00
2001-04-20 02:24      True      False     True      2001-04-20 09:24
2001-08-07 04:48      True      False     True      2001-08-07 11:48
2001-11-24 07:12      False     False     False     2001-11-24 15:12
2002-03-13 09:36      False     False     False     2002-03-13 17:36
2002-06-30 12:00      False     True      True      2002-06-30 19:00
2002-10-17 14:24      False     True      True      2002-10-17 21:24
2003-02-03 16:48      False     False     False     2003-02-04 00:48
2003-05-23 19:12      False     False     True      2003-05-24 02:12
2003-09-09 21:36      False     False     True      2003-09-10 04:36
2003-12-28 00:00      False     False     False     2003-12-28 08:00
*/
// Example of the TimeZone::IsDaylightSavingTime( DateTime ),
// TimeZone::IsDaylightSavingTime( DateTime, DaylightTime ), and 
// TimeZone::ToUniversalTime( DateTime ) methods.
using namespace System;
using namespace System::Globalization;
int main()
{
   String^ headFmt = "{0,-22}{1,-10}{2,-10}{3,-10}{4}";
   
   // Get the local time zone and a base local time.
   TimeZone^ localZone = TimeZone::CurrentTimeZone;
   DateTime localTime = DateTime(2001,1,1);
   Console::WriteLine( "This example of \n"
   "   TimeZone::IsDaylightSavingTime( DateTime ), \n"
   "   TimeZone::IsDaylightSavingTime( "
   "DateTime, DaylightTime* ), and \n"
   "   TimeZone::ToUniversalTime( DateTime )\n"
   "generates the following output, which varies "
   "depending on the \ntime zone in which it is run.\n"
 );
   Console::WriteLine( "The example creates several local "
   "times and the corresponding \nCoordinated Universal "
   "Times (UTC) and shows if they occur in
 \ndaylight "
   "saving time (DST), both for specified years "
   "and for \nany year.\n" );
   Console::WriteLine( "Local time: {0}\n", localZone->StandardName
 );
   Console::WriteLine( headFmt, "Local Date and Time", "2001 DST?",
 "2002 DST?", "Any DST?", "Corresponding UTC" );
   Console::WriteLine( headFmt, "-------------------", "---------",
 "---------", "--------", "-----------------" );
   
   // Create DaylightTime objects for specific years.
   DaylightTime^ daylight2001 = localZone->GetDaylightChanges( 2001 );
   DaylightTime^ daylight2002 = localZone->GetDaylightChanges( 2002 );
   
   // Generate several local times.
   for ( int loopX = 0; loopX <= 10; loopX++
 )
   {
      
      // Calculate the corresponding UTC.
      DateTime utcTime = localZone->ToUniversalTime( localTime );
      
      // Show if dates and times occur in daylight saving 
      // time, for specified years and for any year.
      Console::WriteLine( "{0,-22:yyyy-MM-dd HH:mm}"
      "{1,-10}{2,-10}{3,-10}{4:yyyy-MM-dd HH:mm}", localTime, TimeZone::IsDaylightSavingTime(
 localTime, daylight2001 ), TimeZone::IsDaylightSavingTime( localTime, daylight2002
 ), localZone->IsDaylightSavingTime( localTime ), utcTime );
      
      // Advance to another local time.
      localTime = localTime.AddDays( 109.1 );

   }
}

/*
This example of
   TimeZone::IsDaylightSavingTime( DateTime ),
   TimeZone::IsDaylightSavingTime( DateTime, DaylightTime* ), and
   TimeZone::ToUniversalTime( DateTime )
generates the following output, which varies depending on the
time zone in which it is run.

The example creates several local times and the corresponding
Coordinated Universal Times (UTC) and shows if they occur in
daylight saving time (DST), both for specified years and for
any year.

Local time: Pacific Standard Time

Local Date and Time   2001 DST? 2002 DST? Any DST?  Corresponding UTC
-------------------   --------- --------- --------  -----------------
2001-01-01 00:00      False     False     False     2001-01-01 08:00
2001-04-20 02:24      True      False     True      2001-04-20 09:24
2001-08-07 04:48      True      False     True      2001-08-07 11:48
2001-11-24 07:12      False     False     False     2001-11-24 15:12
2002-03-13 09:36      False     False     False     2002-03-13 17:36
2002-06-30 12:00      False     True      True      2002-06-30 19:00
2002-10-17 14:24      False     True      True      2002-10-17 21:24
2003-02-03 16:48      False     False     False     2003-02-04 00:48
2003-05-23 19:12      False     False     True      2003-05-24 02:12
2003-09-09 21:36      False     False     True      2003-09-10 04:36
2003-12-28 00:00      False     False     False     2003-12-28 08:00
*/
// Example of the TimeZone.IsDaylightSavingTime( DateTime ),
// TimeZone.IsDaylightSavingTime( DateTime, DaylightTime ), and 
// TimeZone.ToUniversalTime( DateTime ) methods.
import System.*;
import System.Globalization.*;

class DaylightTimeDemo
{
    public static void main(String[]
 args)
    {
        final String headFmt = "{0,-22}{1,-10}{2,-10}{3,-10}{4}";

        // Get the local time zone and a base local time.
        TimeZone localZone = TimeZone.get_CurrentTimeZone();
        DateTime localTime = new DateTime(2001, 1, 1);

        Console.WriteLine(("This example of \n"
            + "TimeZone.IsDaylightSavingTime( DateTime ), \n" 
            +  "TimeZone.IsDaylightSavingTime( " 
            + "DateTime, DaylightTime ), and \n" 
            +     "   TimeZone.ToUniversalTime( DateTime )\n" 
            +     "generates the following output, which varies " 
            + "depending on the \ntime zone in which it is
 run.\n"));
        Console.WriteLine(("The example creates several local " 
            + "times and the corresponding \nCoordinated Universal " 
            + "Times (UTC) and shows if they occur in
 \ndaylight " 
            + "saving time (DST), both for specified years
 " 
            + "and for \nany year.\n"));
        Console.WriteLine("Local time: {0}\n", localZone.get_StandardName());
        Console.WriteLine(headFmt, new Object[] { 
            "Local Date and Time", "2001 DST?", "2002 DST?",
 "Any DST?",
            "Corresponding UTC" });
        Console.WriteLine(headFmt, new Object[] { "-------------------"
,
            "---------", "---------", "--------", "-----------------"
 });

        // Create DaylightTime objects for specific years.
        DaylightTime daylight2001 = localZone.GetDaylightChanges(2001);
        DaylightTime daylight2002 = localZone.GetDaylightChanges(2002);

        // Generate several local times.
        for (int loopX = 0; loopX <= 10;
 loopX++) {
            // Calculate the corresponding UTC.
            DateTime utcTime = localZone.ToUniversalTime(localTime);

            // Show if dates and times occur in daylight saving 
            // time, for specified years and for any year.
            Console.WriteLine("{0,-22:yyyy-MM-dd HH:mm}" 
                + "{1,-10}{2,-10}{3,-10}{4:yyyy-MM-dd HH:mm}", new
 Object[]
                { localTime, (System.Boolean)TimeZone.IsDaylightSavingTime(
                localTime, daylight2001), (System.Boolean)
                TimeZone.IsDaylightSavingTime(localTime, daylight2002),
                (System.Boolean)localZone.IsDaylightSavingTime
                (localTime), utcTime });

            // Advance to another local time.
            localTime = localTime.AddDays(109.1);
        }
    } //main
} //DaylightTimeDemo

/*
This example of
   TimeZone.IsDaylightSavingTime( DateTime ),
   TimeZone.IsDaylightSavingTime( DateTime, DaylightTime ), and
   TimeZone.ToUniversalTime( DateTime )
generates the following output, which varies depending on the
time zone in which it is run.

The example creates several local times and the corresponding
Coordinated Universal Times (UTC) and shows if they occur in
daylight saving time (DST), both for specified years and for
any year.

Local time: Pacific Standard Time

Local Date and Time   2001 DST? 2002 DST? Any DST?  Corresponding UTC
-------------------   --------- --------- --------  -----------------
2001-01-01 00:00      False     False     False     2001-01-01 08:00
2001-04-20 02:24      True      False     True      2001-04-20 09:24
2001-08-07 04:48      True      False     True      2001-08-07 11:48
2001-11-24 07:12      False     False     False     2001-11-24 15:12
2002-03-13 09:36      False     False     False     2002-03-13 17:36
2002-06-30 12:00      False     True      True      2002-06-30 19:00
2002-10-17 14:24      False     True      True      2002-10-17 21:24
2003-02-03 16:48      False     False     False     2003-02-04 00:48
2003-05-23 19:12      False     False     True      2003-05-24 02:12
2003-09-09 21:36      False     False     True      2003-09-10 04:36
2003-12-28 00:00      False     False     False     2003-12-28 08:00
*/
プラットフォームプラットフォーム
バージョン情報バージョン情報
参照参照


このページでは「.NET Framework クラス ライブラリ リファレンス」からTimeZone.ToUniversalTime メソッドを検索した結果を表示しています。
Weblioに収録されているすべての辞書からTimeZone.ToUniversalTime メソッドを検索する場合は、下記のリンクをクリックしてください。
 全ての辞書からTimeZone.ToUniversalTime メソッド を検索

英和和英テキスト翻訳>> Weblio翻訳
英語⇒日本語日本語⇒英語
  

辞書ショートカット

すべての辞書の索引

TimeZone.ToUniversalTime メソッドのお隣キーワード
検索ランキング

   

英語⇒日本語
日本語⇒英語
   



TimeZone.ToUniversalTime メソッドのページの著作権
Weblio 辞書 情報提供元は 参加元一覧 にて確認できます。

   
日本マイクロソフト株式会社日本マイクロソフト株式会社
© 2025 Microsoft.All rights reserved.

©2025 GRAS Group, Inc.RSS