我想将时间添加到当前时间,或者换句话说,我有 UTC + 0 的时间,我想要 UTC + 5.00 的时间,我可以减去尽可能多的时间
- 它适用于“(20:15 current_time)-(10)”
- 它适用于“(20:12 current_time)-(10 * 324234小时)”
- 即使“(20:13 current_time)+(1)”添加它也有效
- 但是当“(20:13 current_time)+(5小时)”时它不起作用
代码:
using System;
namespace week3
{
class LocalTime
{
static string Time, City;
static decimal time;
public LocalTime(string city, double add) {
Time = Convert.ToString(DateTime.Now + TimeSpan.FromHours(add));
Time = Time.Substring(11, 5);
time = Convert.ToDecimal(Time.Substring(0, 2) + "." + Time.Substring(3, 2));
City = time.ToString();
Time = City.Substring(0, 2) + ":" + City.Substring(3, 2);
City = city;
DisplayTimeAndCity("", "");
}
static void DisplayTimeAndCity(string x, string y)
{
Console.WriteLine(City + " - " +Time);
}
}
class London : LocalTime {
public London() : base("London", 0) {
}
}
class NewYork : LocalTime
{
public NewYork(): base("NewYork", 5)
{
}
}
class Tokyo : LocalTime
{
public Tokyo(): base("Tokyo", -9)
{
}
}
class HongKong : LocalTime
{
public HongKong(): base("Hong Kong", -8)
{
}
}
class Test {
static void Main() {
London a = new London();
NewYork b = new NewYork();
}
}
}