使用TimeZoneInfo:

static void Main()
{
TimeZoneInfo wa = TimeZoneInfo.FindSystemTimeZoneById
("W. Australia Standard Time"); Console.WriteLine (wa.Id); // W. Australia Standard Time
Console.WriteLine (wa.DisplayName); // (GMT+08:00) Perth
Console.WriteLine (wa.BaseUtcOffset); // 08:00:00
Console.WriteLine (wa.SupportsDaylightSavingTime); // True foreach (TimeZoneInfo.AdjustmentRule rule in wa.GetAdjustmentRules())
{
Console.WriteLine ("Rule: applies from " + rule.DateStart +
" to " + rule.DateEnd); Console.WriteLine (" Delta: " + rule.DaylightDelta); Console.WriteLine (" Start: " + FormatTransitionTime
(rule.DaylightTransitionStart, false)); Console.WriteLine (" End: " + FormatTransitionTime
(rule.DaylightTransitionEnd, true));
Console.WriteLine();
}
} static string FormatTransitionTime (TimeZoneInfo.TransitionTime tt,
bool endTime)
{
if (endTime && tt.IsFixedDateRule
&& tt.Day == 1 && tt.Month == 1
&& tt.TimeOfDay == DateTime.MinValue)
return "-"; string s;
if (tt.IsFixedDateRule)
s = tt.Day.ToString();
else
s = "The " +
"first second third fourth last".Split() [tt.Week - 1] +
" " + tt.DayOfWeek + " in"; return s + " " + DateTimeFormatInfo.CurrentInfo.MonthNames [tt.Month-1]
+ " at " + tt.TimeOfDay.TimeOfDay;
}

DateTime和daylight保存:

DaylightTime changes = TimeZone.CurrentTimeZone.GetDaylightChanges (2008);
TimeSpan halfDelta = new TimeSpan (changes.Delta.Ticks / 2); DateTime utc1 = changes.End.ToUniversalTime() - halfDelta;
DateTime utc2 = utc1 - changes.Delta; // Converting these variables to local times demonstrates why you should use
// UTC and not local time if your code relies on time moving forward: DateTime loc1 = utc1.ToLocalTime(); // (Pacific Standard Time)
DateTime loc2 = utc2.ToLocalTime();
Console.WriteLine (loc1); // 2/11/2008 1:30:00 AM
Console.WriteLine (loc2); // 2/11/2008 1:30:00 AM
Console.WriteLine (loc1 == loc2); // True Console.Write (loc1.ToString ("o")); // 2008-11-02T02:30:00.0000000-08:00
Console.Write (loc2.ToString ("o")); // 2008-11-02T02:30:00.0000000-07:00 Console.WriteLine (loc1.ToUniversalTime() == utc1); // True
Console.WriteLine (loc2.ToUniversalTime() == utc2); // True

写一个自定义格式provider:

public class WordyFormatProvider : IFormatProvider, ICustomFormatter
{
static readonly string[] _numberWords =
"zero one two three four five six seven eight nine minus point".Split(); IFormatProvider _parent; // Allows consumers to chain format providers public WordyFormatProvider() : this (CultureInfo.CurrentCulture) { }
public WordyFormatProvider (IFormatProvider parent)
{
_parent = parent;
} public object GetFormat (Type formatType)
{
if (formatType == typeof (ICustomFormatter)) return this;
return null;
} public string Format (string format, object arg, IFormatProvider prov)
{
// If it's not our format string, defer to the parent provider:
if (arg == null || format != "W")
return string.Format (_parent, "{0:" + format + "}", arg); StringBuilder result = new StringBuilder();
string digitList = string.Format (CultureInfo.InvariantCulture,
"{0}", arg);
foreach (char digit in digitList)
{
int i = "0123456789-.".IndexOf (digit);
if (i == -1) continue;
if (result.Length > 0) result.Append (' ');
result.Append (_numberWords[i]);
}
return result.ToString();
}
}

重载相等语义:

public struct Area : IEquatable <Area>
{
public readonly int Measure1;
public readonly int Measure2; public Area (int m1, int m2)
{
Measure1 = m1;
Measure2 = m2;
} public override bool Equals (object other)
{
if (!(other is Area)) return false;
return Equals ((Area) other); // Calls method below
} public bool Equals (Area other) // Implements IEquatable<Area>
{
return Measure1 == other.Measure1 && Measure2 == other.Measure2
|| Measure1 == other.Measure2 && Measure2 == other.Measure1;
} public override int GetHashCode()
{
if (Measure1 > Measure2)
return Measure1 * 37 + Measure2; // 37 = a prime number
else
return Measure2 * 37 + Measure1;
} public static bool operator == (Area a1, Area a2)
{
return a1.Equals (a2);
} public static bool operator != (Area a1, Area a2)
{
return !a1.Equals (a2);
}
}

实现IComparable接口:

public struct Note : IComparable<Note>, IEquatable<Note>, IComparable
{
int _semitonesFromA; public Note (int semitonesFromA)
{
_semitonesFromA = semitonesFromA;
} public int CompareTo (Note other) // Generic IComparable<T>
{
if (Equals (other)) return 0; // Fail-safe check
return _semitonesFromA.CompareTo (other._semitonesFromA);
} int IComparable.CompareTo (object other) // Nongeneric IComparable
{
if (!(other is Note))
throw new InvalidOperationException ("CompareTo: Not a note");
return CompareTo ((Note) other);
} public static bool operator < (Note n1, Note n2)
{
return n1.CompareTo (n2) < 0;
} public static bool operator > (Note n1, Note n2)
{
return n1.CompareTo (n2) > 0;
} public bool Equals (Note other) // for IEquatable<Note>
{
return _semitonesFromA == other._semitonesFromA;
} public override bool Equals (object other)
{
if (!(other is Note)) return false;
return Equals ((Note) other);
} public override int GetHashCode()
{
return _semitonesFromA.GetHashCode();
} public static bool operator == (Note n1, Note n2)
{
return n1.Equals (n2);
} public static bool operator != (Note n1, Note n2)
{
return !(n1 == n2);
}
}

C# 3.0 基本框架的更多相关文章

  1. Yii2.0高级框架数据库增删改查的一些操作(转)

    yii2.0框架是PHP开发的一个比较高效率的框架,集合了作者的大量心血,下面通过用户为例给大家详解yii2.0高级框架数据库增删改查的一些操作 --------------------------- ...

  2. 使用DotNetOpenAuth搭建OAuth2.0授权框架

    标题还是一如既往的难取. 我认为对于一个普遍问题,必有对应的一个简洁优美的解决方案.当然这也许只是我的一厢情愿,因为根据宇宙法则,所有事物总归趋于混沌,而OAuth协议就是混沌中的产物,不管是1.0. ...

  3. Yii2.0高级框架数据库增删改查的一些操作

    yii2.0框架是PHP开发的一个比较高效率的框架,集合了作者的大量心血,下面通过用户为例给大家详解yii2.0高级框架数据库增删改查的一些操作 --------------------------- ...

  4. Tao 1.2.0图形框架发布

    Tao 1.2.0图形框架发布         Tao图形框架是方便在Mono和.Net环境下进行游戏相关开发的库绑定和实用工具集.目前,对以下库提供支持: Cg - [Cg website] Dev ...

  5. 从壹开始前后端分离【 .NET Core2.0 +Vue2.0 】框架之四 || Swagger的使用 3.2

    前言 如果想直接在域名的根目录直接加载 swagger 比如访问:localhost:8001 就能访问,可以这样设置: app.UseSwaggerUI(c => { c.SwaggerEnd ...

  6. 从壹开始前后端分离【 .NET Core2.0 +Vue2.0 】框架之十二 || 三种跨域方式比较,DTOs(数据传输对象)初探

    更新反馈 1.博友@落幕残情童鞋说到了,Nginx反向代理实现跨域,因为我目前还没有使用到,给忽略了,这次记录下,为下次补充.此坑已填 2.提示:跨域的姊妹篇——<三十三║ ⅖ 种方法实现完美跨 ...

  7. OAuth 2.0 RFC 框架 中文

    Internet Engineering Task Force (IETF) D. Hardt, Ed.Request for Comments: 6749 MicrosoftObsoletes: 5 ...

  8. Chisel辅助iOS 应用程序调试,MusicApp模仿酷狗4.0 UI框架

    本文转载至 http://www.cocoachina.com/ios/20140825/9446.html Chisel Chisel集合了大量的LLDB 命令来辅助iOS 应用程序调试,并支持添 ...

  9. Z从壹开始前后端分离【 .NET Core2.0/3.0 +Vue2.0 】框架之四 || Swagger的使用 3.2

    本文梯子 本文3.0版本文章 前言 一.swagger的一般用法 0.设置swagger页面为首页——开发环境 1.设置默认直接首页访问 —— 生产环境 2.为接口添加注释 3.对 Model 也添加 ...

  10. OAuth 2.0授权框架详解

    目录 简介 OAuth的构成 refresh Token Authorization Code模式 隐式授权 Resource Owner 授权密码认证 Client 认证授权 github的OAut ...

随机推荐

  1. 恒天云技术分享系列4 – OpenStack网络攻击与防御

    恒天云技术分享系列:http://www.hengtianyun.com/download-show-id-13.html 云主机的网络结构本质上和传统的网络结构一致,区别大概有两点. 1.软网络管理 ...

  2. IP查找工具——angry IP Scanner

    作用] 若树莓派没有屏幕可通过该工具查找树莓派的IP地址.例如下图的树莓派IP地址可能为192.168.1.107. 图1 IP scan查找树莓派IP地址

  3. gpg: no valid OpenPGP data found

    gpg: no valid OpenPGP data found

  4. 起底多线程同步锁(iOS)

    iOS/MacOS为多线程.共享内存(变量)提供了多种的同步解决方案(即同步锁),对于这些方案的比较,大都讨论了锁的用法以及锁操作的开销,然后就开销表现排个序.春哥以为,最优方案的选用还是看应用场景, ...

  5. vs2015中升级Nuget后,找不到Umbraco安装包问题

    打开VS2015, Tools=>Extensions and Updates=> Updates => Visual Studio Gallery   在这里check一下是否有N ...

  6. C/C++语言中#的神奇作用:把宏参数字符串化/贴合宏参数

    宏中"#"和"##"的用法 一.一般用法   我们使用#把宏参数变为一个字符串,用##把两个宏参数贴合在一起. #define STR(s)      #s # ...

  7. Postfix配置Q&A

    原文地址:http://space.doit.com.cn/51460/viewspace-4943.html 在配置Postfix中遇到的一些问题及相关的解决方法,希望在遇到相同的问题时能起参考的作 ...

  8. Android虚拟环境的工具集Genymotion完整安装教程

    Genymotion提供Android虚拟环境的工具集.相信很多Android开发者一定受够了速度慢.体验差效率及其地下的官方模拟器了.如果你没有物理机器,又不想忍受官方模拟器的折磨,Genymoti ...

  9. Python标准库:内置函数reversed(seq)

    本函数是返回序列seq的反向訪问的迭代子. 样例: #reversed() for i in reversed([2, 3, 4, 5]): print(i, end = ',') 结果输出例如以下: ...

  10. 新闻客户端nices

    https://github.com/android-cjj/nices