「時差2」
「時差」アプリをバージョンアップして、G20参加国に対応させました。
実行ファイルをダウンロードできますが、実行する際に「警告」が出ます。自己責任で実行してください。このファイルを実行して生じた如何なる損害にも責任は負えません。
実行ファイルをダウンロードしない場合は、以下の要領でプロジェクトを作成してください。
なお、各国のTimeZoneInfoをお知りになりたい方は、コンソールアプリ「TimeZone」を参考にしてください。

開発環境:Visual
Studio 2019
プロジェクト名:TimeDifference
言語:C#
プラットフォーム:Windows
プロジェクトタイプ:ディスクトップ
Windowsフォームアプリケーション(.NET Framework4.7.2)
(注意)このアプリケーションを実行して生じた如何なる損害等に責任は負えません。
Form1.Property
Form1
Text=時差
<ConboBox>
Font.Size=14
Items(コレクション)=
韓国
中国
インドネシア
インド
サウジアラビア
フランス
ドイツ
イタリア
イギリス
ロシア
トルコ
カナダ
メキシコ
アメリカ
アルゼンチン
ブラジル
オーストラリア
南アフリカ
東京
<Label>
Name=labelJpNow
Text=日本時間
<TextBox>
Name=textBoxJpNow
Enabled=false
Font.Size=14
<Lbel>
Name=labelLocalTime
Text=LocalTime
<TextBox>
Name=textBoxLocalTime
Enabled=false
Font.Size=14
<Label>
Name=labelTimeZoneID
Text=TimeZoneID
<TextBox>
Name=textBoxTimeZoneID
Enabled=false
Font.Size=14
<Label>
Name=labelDisplayName
Text=DisplayName
<TextBox>
Name=textBoxDisplayName
Enabled=false
Font.Size=14
<Label>
Name=labelStandardName
Text=StandardName
<TextBox>
Name=textBoxStandardName
Enabled=false
Font.Size=14
<Label>
Name=labelDaylightName
Text=DaylightName
<TextBox>
Name=textBoxDaylightName
Enabled=false
Font.Size=14
<Label>
Name=labelSupportsDaylight
Text=SupportsDaylight
<TextBox>
Name=textBoxSupportsDaylight
Enabled=false
Font.Size=14
<Label>
Name=labelTimeDifference
Text=TimeDifference
<TextBox>
Name=textBoxTimeDifference
Enabled=false
Font.Size=14
<Timer1>
interval=1000
Enabled=true
Form1.cs
using System.Windows.Forms;
namespace TimeDifference
{
public partial class Form1 : Form
{
string tz = "Tokyo Standard Time";public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
GetTimeZoneInfoToText();
}
private void Timer1_Tick(object sender, EventArgs e)
{
GetTimeDifference();
}
private void ComboBox1_SelectedIndexChanged(object sender, EventArgs e)
{
var index = comboBox1.SelectedItem;
switch (index)
{
case "韓国":
tz = "Korea Standard Time";
GetTimeZoneInfoToText();
break;
case "中国":
tz = "China Standard Time";
GetTimeZoneInfoToText();
break;
case "インドネシア":
tz = "SE Asia Standard Time";
GetTimeZoneInfoToText();
break;
case "インド":
tz = "India Standard Time";
GetTimeZoneInfoToText();
break;
case "サウジアラビア":
tz = "Arab Standard Time";
GetTimeZoneInfoToText();
break;
case "フランス":
tz = "Romance Standard Time";
GetTimeZoneInfoToText();
break;
case "ドイツ":
tz = "W. Europe Standard Time";
GetTimeZoneInfoToText();
break;
case "イタリア":
tz = "W. Europe Standard Time";
GetTimeZoneInfoToText();
break;
case "イギリス":
tz = "GMT Standard Time";
GetTimeZoneInfoToText();
break;
case "ロシア":
tz = "Russian Standard Time";
GetTimeZoneInfoToText();
break;
case "トルコ":
tz = "Turkey Standard Time";
GetTimeZoneInfoToText();
break;
case "カナダ":
tz = "Atlantic Standard Time";
GetTimeZoneInfoToText();
break;
case "メキシコ":
tz = "Central Standard Time (Mexico)";
GetTimeZoneInfoToText();
break;
case "アメリカ合衆国":
tz = "Eastern Standard Time";
GetTimeZoneInfoToText();
break;
case "アルゼンチン":
tz = "Argentina Standard Time";
GetTimeZoneInfoToText();
break;
case "ブラジル":
tz = "E. South America Standard Time";
GetTimeZoneInfoToText();
break;
case "オーストラリア":
tz = "AUS Eastern Standard Time";
GetTimeZoneInfoToText();
break;
case "南アフリカ":
tz = "South Africa Standard Time";
GetTimeZoneInfoToText();
break;
case "東京":
tz = "Tokyo Standard Time";
GetTimeZoneInfoToText();
break;
}
}
public void GetTimeDifference()
{
DateTimeOffset utc = DateTimeOffset.UtcNow;
TimeZoneInfo timeZoneInfo = TimeZoneInfo.FindSystemTimeZoneById(tz);
DateTimeOffset jpnow = DateTimeOffset.Now;
DateTimeOffset localTime = TimeZoneInfo.ConvertTime(utc, timeZoneInfo);
textBoxJpNow.Text = jpnow.DateTime.ToString("yyyy/MM/dd HH:mm:ss");
textBoxLocalTime.Text = localTime.DateTime.ToString("yyyy/MM/dd HH:mm:ss");
textBoxTimeDifference.Text = (localTime.DateTime - jpnow.DateTime).ToString();
}
public void GetTimeZoneInfoToText()
{
TimeZoneInfo timeZoneInfo = TimeZoneInfo.FindSystemTimeZoneById(tz);
textBoxTimeZoneID.Text = timeZoneInfo.Id;
textBoxDisplayName.Text = timeZoneInfo.DisplayName;
textBoxStandardName.Text = timeZoneInfo.StandardName;
textBoxDaylightName.Text = timeZoneInfo.DaylightName;
_ = timeZoneInfo.SupportsDaylightSavingTime ? textBoxSupportsDaylight.Text = "有り"
: textBoxSupportsDaylight.Text = "無し";
}
}
}