chore: 首次簽入 Thinkyu ASP.NET 專案
- 加入 Visual Studio / ASP.NET .gitignore - 排除建置輸出、IDE 設定、NuGet packages、大型 MSI 安裝檔
This commit is contained in:
@@ -0,0 +1,145 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
|
||||
namespace TestConsoleApp
|
||||
{
|
||||
internal class Program
|
||||
{
|
||||
static void Main(string[] args)
|
||||
{
|
||||
var dt1 = new DateTime(2026, 3, 29, 4, 0, 0);
|
||||
var dt2 = new DateTime(2026, 3, 29, 6, 0, 0);
|
||||
var dt3 = new DateTime(2026, 3, 29, 14, 0, 0);
|
||||
|
||||
var dnt1 = DateAndTime.GetNow("", dt1);
|
||||
var dnt2 = DateAndTime.GetNow("", dt2);
|
||||
var dnt3 = DateAndTime.GetNow("", dt3);
|
||||
|
||||
Console.WriteLine(string.Format("{0:yyyy-MM-dd} {1:yyyy-MM-dd} {2} {3:yyyy-MM-dd} {4}", dnt1.TwWorkDate, dnt1.TwCalendarDate, dnt1.TwTime, dnt1.LocalDate, dnt1.LocalTime));
|
||||
Console.WriteLine(string.Format("{0:yyyy-MM-dd} {1:yyyy-MM-dd} {2} {3:yyyy-MM-dd} {4}", dnt2.TwWorkDate, dnt2.TwCalendarDate, dnt2.TwTime, dnt2.LocalDate, dnt2.LocalTime));
|
||||
Console.WriteLine(string.Format("{0:yyyy-MM-dd} {1:yyyy-MM-dd} {2} {3:yyyy-MM-dd} {4}", dnt3.TwWorkDate, dnt3.TwCalendarDate, dnt3.TwTime, dnt3.LocalDate, dnt3.LocalTime));
|
||||
Console.WriteLine("按 ENTER 結束");
|
||||
Console.ReadLine();
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 30 小時制的日期類別
|
||||
/// </summary>
|
||||
public class DateAndTime
|
||||
{
|
||||
/// <summary>
|
||||
/// 台灣工作日期
|
||||
/// </summary>
|
||||
public DateTime TwWorkDate;
|
||||
|
||||
/// <summary>
|
||||
/// 台灣日曆日期
|
||||
/// </summary>
|
||||
public DateTime TwCalendarDate;
|
||||
|
||||
/// <summary>
|
||||
/// 台灣時間
|
||||
/// </summary>
|
||||
public string TwTime;
|
||||
|
||||
/// <summary>
|
||||
/// 當地日期
|
||||
/// </summary>
|
||||
public DateTime LocalDate;
|
||||
|
||||
/// <summary>
|
||||
/// 當地時間
|
||||
/// </summary>
|
||||
public string LocalTime;
|
||||
|
||||
/// <summary>
|
||||
/// 時區名稱
|
||||
/// </summary>
|
||||
public string TimezoneName;
|
||||
|
||||
/// <summary>
|
||||
/// 時區ID
|
||||
/// </summary>
|
||||
public string TimeZoneID;
|
||||
|
||||
public DateAndTime(DateTime twWorkDate, DateTime twCalendarDate, string twTime, DateTime localDate, string localTime, string timezoneName, string timezoneID) : base()
|
||||
{
|
||||
this.TwWorkDate = twWorkDate;
|
||||
this.TwCalendarDate = twCalendarDate;
|
||||
this.TwTime = twTime;
|
||||
this.LocalDate = localDate;
|
||||
this.LocalTime = localTime;
|
||||
TimezoneName = timezoneName;
|
||||
TimeZoneID = timezoneID;
|
||||
}
|
||||
|
||||
public static DateTime 轉換時區(string 時區, DateTime 日期, string 時間)
|
||||
{
|
||||
// 解析30小時制(小時可能 >= 24,表示跨入隔日凌晨)
|
||||
var parts = 時間.Split(':');
|
||||
var timeSpan = new TimeSpan(int.Parse(parts[0]), int.Parse(parts[1]), int.Parse(parts[2]));
|
||||
var sourceTime = 日期.Date.Add(timeSpan);
|
||||
|
||||
if (string.IsNullOrEmpty(時區) || string.Compare(時區, "Taipei Standard Time") == 0)
|
||||
{
|
||||
return sourceTime;
|
||||
}
|
||||
|
||||
// 重要:將 Kind 設為 Unspecified
|
||||
sourceTime = DateTime.SpecifyKind(sourceTime, DateTimeKind.Unspecified);
|
||||
|
||||
// 轉換到目標時區
|
||||
var sourceZone = TimeZoneInfo.FindSystemTimeZoneById("Taipei Standard Time");
|
||||
var targetZone = TimeZoneInfo.FindSystemTimeZoneById(時區);
|
||||
|
||||
var utcTime = TimeZoneInfo.ConvertTimeToUtc(sourceTime, sourceZone);
|
||||
var targetTime = TimeZoneInfo.ConvertTimeFromUtc(utcTime, targetZone);
|
||||
|
||||
return targetTime;
|
||||
}
|
||||
|
||||
public static DateAndTime GetNow(string bpeno, DateTime twNow)
|
||||
{
|
||||
string timezoneID = "Pacific Standard Time";
|
||||
string timezoneName = "美西";
|
||||
|
||||
var twCalendarDate = twNow.Date;
|
||||
var twWorkDate = twNow.Date;
|
||||
var localNow = 轉換時區(timezoneID, twNow.Date, twNow.ToString("HH:mm:ss"));
|
||||
var localDate = localNow.Date;
|
||||
var twHourOffset = 0;
|
||||
var localHourOffset = 0;
|
||||
|
||||
// 06:00 之前算前一天
|
||||
if (twNow.TimeOfDay < new TimeSpan(6, 0, 0))
|
||||
{
|
||||
twWorkDate = twWorkDate.AddDays(-1);
|
||||
twHourOffset = 24;
|
||||
}
|
||||
if (localNow.TimeOfDay < new TimeSpan(6, 0, 0))
|
||||
{
|
||||
localDate = localDate.AddDays(-1);
|
||||
localHourOffset = 24;
|
||||
}
|
||||
|
||||
return new DateAndTime(
|
||||
twWorkDate,
|
||||
twCalendarDate,
|
||||
string.Format("{0:00}:{1:00}:{2:00}", twNow.TimeOfDay.Hours + twHourOffset, twNow.TimeOfDay.Minutes, twNow.Second),
|
||||
localDate,
|
||||
string.Format("{0:00}:{1:00}:{2:00}", localNow.TimeOfDay.Hours + localHourOffset, localNow.TimeOfDay.Minutes, localNow.Second),
|
||||
timezoneName,
|
||||
timezoneID
|
||||
);
|
||||
}
|
||||
|
||||
public static DateAndTime GetNow(string bpeno)
|
||||
{
|
||||
var twNow = DateTime.UtcNow.AddHours(8);
|
||||
return GetNow(bpeno, twNow);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,33 @@
|
||||
using System.Reflection;
|
||||
using System.Runtime.CompilerServices;
|
||||
using System.Runtime.InteropServices;
|
||||
|
||||
// 組件的一般資訊是由下列的屬性集控制。
|
||||
// 變更這些屬性的值即可修改組件的相關
|
||||
// 資訊。
|
||||
[assembly: AssemblyTitle("TestConsoleApp")]
|
||||
[assembly: AssemblyDescription("")]
|
||||
[assembly: AssemblyConfiguration("")]
|
||||
[assembly: AssemblyCompany("")]
|
||||
[assembly: AssemblyProduct("TestConsoleApp")]
|
||||
[assembly: AssemblyCopyright("Copyright © 2026")]
|
||||
[assembly: AssemblyTrademark("")]
|
||||
[assembly: AssemblyCulture("")]
|
||||
|
||||
// 將 ComVisible 設為 false 可對 COM 元件隱藏
|
||||
// 組件中的類型。若必須從 COM 存取此組件中的類型,
|
||||
// 的類型,請在該類型上將 ComVisible 屬性設定為 true。
|
||||
[assembly: ComVisible(false)]
|
||||
|
||||
// 下列 GUID 為專案公開 (Expose) 至 COM 時所要使用的 typelib ID
|
||||
[assembly: Guid("18c0ec59-f66b-48a7-ab66-04263c52bd6b")]
|
||||
|
||||
// 組件的版本資訊由下列四個值所組成:
|
||||
//
|
||||
// 主要版本
|
||||
// 次要版本
|
||||
// 組建編號
|
||||
// 修訂
|
||||
//
|
||||
[assembly: AssemblyVersion("1.0.0.0")]
|
||||
[assembly: AssemblyFileVersion("1.0.0.0")]
|
||||
@@ -0,0 +1,47 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<Project ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
|
||||
<PropertyGroup>
|
||||
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
|
||||
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
|
||||
<ProjectGuid>{18C0EC59-F66B-48A7-AB66-04263C52BD6B}</ProjectGuid>
|
||||
<OutputType>Exe</OutputType>
|
||||
<RootNamespace>TestConsoleApp</RootNamespace>
|
||||
<AssemblyName>TestConsoleApp</AssemblyName>
|
||||
<TargetFrameworkVersion>v3.5</TargetFrameworkVersion>
|
||||
<FileAlignment>512</FileAlignment>
|
||||
<Deterministic>true</Deterministic>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
|
||||
<PlatformTarget>AnyCPU</PlatformTarget>
|
||||
<DebugSymbols>true</DebugSymbols>
|
||||
<DebugType>full</DebugType>
|
||||
<Optimize>false</Optimize>
|
||||
<OutputPath>bin\Debug\</OutputPath>
|
||||
<DefineConstants>DEBUG;TRACE</DefineConstants>
|
||||
<ErrorReport>prompt</ErrorReport>
|
||||
<WarningLevel>4</WarningLevel>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
|
||||
<PlatformTarget>AnyCPU</PlatformTarget>
|
||||
<DebugType>pdbonly</DebugType>
|
||||
<Optimize>true</Optimize>
|
||||
<OutputPath>bin\Release\</OutputPath>
|
||||
<DefineConstants>TRACE</DefineConstants>
|
||||
<ErrorReport>prompt</ErrorReport>
|
||||
<WarningLevel>4</WarningLevel>
|
||||
</PropertyGroup>
|
||||
<ItemGroup>
|
||||
<Reference Include="System" />
|
||||
<Reference Include="System.Core" />
|
||||
<Reference Include="System.Xml.Linq" />
|
||||
<Reference Include="System.Data.DataSetExtensions" />
|
||||
<Reference Include="System.Data" />
|
||||
<Reference Include="System.Xml" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Compile Include="Program.cs" />
|
||||
<Compile Include="Properties\AssemblyInfo.cs" />
|
||||
</ItemGroup>
|
||||
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
|
||||
</Project>
|
||||
Reference in New Issue
Block a user