私はサードパーティのライブラリで使用されるDateTimesを作成しています(もちろん私は制御できません)。このサードパーティ ライブラリを使用して、作成中の DateTimes を含むいくつかのファイルを書き込んでいます。
日付を別の形式で出力したいのですが、DateTime がサード パーティによってどのように変換されるかを制御できません。また、DateTime を変換するたびにカルチャ情報を変更することも、DateTime を継承して ToString をオーバーライドすることもできません。できる)。
特定のフォーマットを DateTime にバインドして、ToString メソッドを呼び出すたびにこのフォーマットが使用されるようにする方法はありますか?
DateTime firstDate = new DateTime(2013, 02, 07); //I would like this DateTime to be printed this way: 2013-02-07
DateTime secondDate = new DateTime(2013, 02, 07); //I would like this DateTime to be printed this way: Thursday, February 07, 2013
thirdPartyLib.SetFirstDate(firstDate);
thirdPartyLib.SetSecondDate(secondDate);
thirdPartyLib.PrintBothDate(); //This method convert both DateTime in strings