C# 如何獲取(抓取)目前系統當前時區(UTC/GMT)程式
C# 如何獲取(抓取)目前系統當前時區(UTC/GMT)程式
資料來源: https://bbs.csdn.net/topics/310100284
線上編譯測試: https://www.tutorialspoint.com/compile_csharp_online.php
GITHUB: https://github.com/jash-git/CS_Get_UTC_Zone
Code:
using System.IO;
using System;
class Program
{
static void Main()
{
int offset = TimeZone.CurrentTimeZone.GetUtcOffset(DateTime.Now).Hours;
string sign = "";
if(offset > 0) {
sign = " + ";
}
else
{
sign = " - ";
}
string zone = "UTC(GMT)" + sign + offset;
Console.WriteLine(zone);
}
}