public class Common
{
CSScript cs = new CSScript();
//*** strTimeに入っている値を数値(分)に変換して返します。 ***
// strTime : 計算対象の時間。必ずhh:mm形式で入力するようにしてください。
// 変換できないときは0を返します。
public int 時間_数値化(string strTime)
{
int wkHour;
int wkMinute;
if( strTime == null)
{
return 0;
}
//時間を取得
wkHour = (int)CSScript.Val(CSScript.Left(strTime, strTime.IndexOf(":", 1) - 1));
wkMinute = (int)CSScript.Val(CSScript.Right(strTime, 2));
try{
return wkHour * 60 + wkMinute;
}catch(Exception){
return 0;
}
}
//*** ↑の処理で数値化された時間を元に戻します。変換失敗時は空文字列を返します ***
public string 数値_時間化(int lngTime)
{
if(lngTime == 0)
{
return "";
}
try
{
return CSScript.Fix(lngTime / 60, 0) + ":" + string.Format( "00", lngTime % 60);
}catch(Exception){
return "";
}
}
//*** 月末日付を取得します ***
// 変換できなかった場合は0を返します。
public int 月末日付(string strMonth)
{
DateTime dt =DateTime.Now;
return DateTime.DaysInMonth(dt.Year, (int)CSScript.Val(strMonth));
}
VBで作ったのをC#にする際に、勢いのままクラスも直していたのでついでなので乗せておきます。
ってかなんかインデントがおかしい
2007年11月17日土曜日
[C#]時間数値化、数値時間化、月末日付をまとめたC#用クラス
ラベル: C#
登録:
コメントの投稿 (Atom)
0 件のコメント:
コメントを投稿